sparse-intern-71089
05/17/2021, 7:08 PMfull-dress-10026
05/17/2021, 7:08 PMexport async function getApproximateNumberOfMessages(queueUrl: pulumi.Input<string>): Promise<number> {
const queueUrlStr = pulumi.output(queueUrl).get()
}
Example aws api function call.full-dress-10026
05/17/2021, 7:10 PMfull-dress-10026
05/17/2021, 7:10 PMconst cbFn = new aws.lambda.CallbackFunction(`${name}-callback-fn`, {
name: `${name}-handler`,
role: args.role,
callback: async function (event: aws.cloudwatch.EventRuleEvent) {
await getApproximateNumberOfMessages(queueUrl)
}
});
bored-oyster-3147
05/17/2021, 7:13 PMOutput.apply(..)
to interpolate the values into the function that you need to, or you could set the values that the function needs as environment variables on the lambda and have the lambda access themfull-dress-10026
05/17/2021, 7:14 PMbored-oyster-3147
05/17/2021, 7:15 PMfull-dress-10026
05/17/2021, 7:16 PMqueueUrl.apply(url => {
const cbFn = new aws.lambda.CallbackFunction(`${name}-callback-fn`, {
name: `${name}-handler`,
role: args.role,
callback: async function (event: aws.cloudwatch.EventRuleEvent) {
await getApproximateNumberOfMessages(url)
}
});
})
bored-oyster-3147
05/17/2021, 7:17 PMCallbackFunction
? Because all I see here is `Function`: https://www.pulumi.com/docs/reference/pkg/aws/lambda/?iaid=no-experiment
Then I could explain betterfull-dress-10026
05/17/2021, 7:18 PMfull-dress-10026
05/17/2021, 7:19 PMbored-oyster-3147
05/17/2021, 7:21 PMFunctionArgs
takes in an Archive
in the code
input. So you could make your archive with a StringAsset
after interpolating your queue URL.
So your code could be:
var code = queueUrl.apply(url => {
return @"async function (event: aws.cloudwatch.EventRuleEvent) {
var url = ${url};
// do work
}";
});
Using whatever string interpolation looks like. And now your function is an Output<string>
which can be passedbored-oyster-3147
05/17/2021, 7:21 PMfull-dress-10026
05/17/2021, 7:21 PMfull-dress-10026
05/17/2021, 7:22 PMfull-dress-10026
05/17/2021, 7:22 PMbored-oyster-3147
05/17/2021, 7:22 PMbored-oyster-3147
05/17/2021, 7:23 PMfull-dress-10026
05/17/2021, 7:24 PMfull-dress-10026
05/17/2021, 7:27 PMfull-dress-10026
05/17/2021, 7:27 PMbored-oyster-3147
05/17/2021, 7:27 PMcallback
parameter. Pulumi is not examining the inside of your function, it can't really do that. All it can do is serialize the function not knowing it's contents. It has no awareness of the fact that your function is calling out to some Input<T>
or Output<T>
The function serialization exists purely as a QOL thing in the languages that support it so that you can write your lambda in the same file/language that you are writing your pulumi codebored-oyster-3147
05/17/2021, 7:27 PM