Azure / Azure/azure-functions-nodejs-library
Support imperative runtime binding
- Dominant language
- TypeScript
- Stars
- 70
- Forks
- 35
- Avg merge
- 4d 18h
- Merged PRs (30d)
- 6
Description
#### Investigative information
I am trying to write a generic HTTP webhook that determines the queue to put the payload into based on some piece of data within the payload, that can only be determined at runtime. As per the [binding documentation](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-expressions-patterns#binding-at-runtime) this imperative binding is only possible on .NET runtimes. This feels like a siginificant omission from the new Node.js programming model.
#### Repro steps
Create a function with a `storageQueue` output binding. The queue name must be hardcoded and cannot be altered at runtime.
```
const queueOutput = output.storageQueue({
connection: 'AzureWebJobsStorage',
queueName: 'hardcoded',
});
export async function httpFunction(request: HttpRequest, context: InvocationContext): Promise {
// ...
queueOutput.queueName = queueName;
context.extraOutputs.set(queueOutput, payload);
// ...
}
```
#### Expected behavior
I should be able to override `queueName` within the function handler body as per the above. Alternatively, it could be specified as an output binding (`queueName: '{queueName}'`) and then a runtime output object provided as a parameter to `extraOutputs.set()`.
#### Actual behavior
Setting the `queueName` property as per the above does not cause an error, but is ignored and the payload created on the `hardcoded` queue.
#### Known workarounds
I am currently having to define an array of `storageQueue` objects, specify each of them in the `extraOutputs` array, and then determine which to actually populate at runtime. As the list of possible queues grows, this is becoming unwieldy.
Alternatively, I could create a separate http trigger function for each queue, but this involves a large amount of boilerplate.
Contributor guide
Assessment
This issue has not been assessed yet.