https://pulumi.com logo
Title
a

alert-gpu-18471

11/21/2022, 2:38 PM
Hello folks! I was wondering if anyone can help me solve following issue for me. I was trying to invoke Lambda function, however,
pulumi.Output
has been bugging me. The function works if I put raw string in the code, but, not with
pulumi.interpolate
.
I will provide some code in comment for the context! Thank you in advance. 🙇‍♂️🏻
So, it is basically a Lambda function to start Glue crawler.
const ogimGlueCrawler = new aws.glue.Crawler("ogim-report-crawler", {
    databaseName: glueCatalogDatabase.name,
    role: monitoringRoleArn,

    s3Targets: [{
        path: pulumi.interpolate`s3://${bucketName}/ogim`,
    }],
});

const pythonLambda = new aws.lambda.Function("python-lambda-function", {
    code: new pulumi.asset.AssetArchive({
        ".": new pulumi.asset.FileArchive("./lambda"),
    }),
    runtime: aws.lambda.Python3d8Runtime,
    timeout: 30,
    handler: "handler.glue_handler",
    role: lambdaRole.arn
});

const glueLambdaInvocation = new aws.lambda.Invocation("python-lambada-invocation", {
    functionName: pulumi.interpolate`${pythonLambda.name}`,
    input: JSON.stringify({
        crawler_name: pulumi.interpolate`${ogimGlueCrawler.name}`,
        dummy_number: Math.floor(Math.random() * 1000),  // To force lambda to run
    }),
});
I ditched some variables to show the code clearer.
l

little-cartoon-10569

11/21/2022, 6:43 PM
You need to have the output be the entire value set into
input
. You can't set
input
to be a string, then embed an output into the string. That will just call
toString()
on the output, which isn't what you want.
You can
apply
originGlueCrawler.name, and build the JSON string in there. That way, the output will contain JSON,
input
can decide outputs, and the JSON gets correctly put into the payload.
a

alert-gpu-18471

11/22/2022, 3:20 AM
@little-cartoon-10569 Thanks a lot! I just figured out that the issue was the input’s Json part. I fixed it according to your solution and now it works! Thank you 🙂