https://pulumi.com logo
Title
w

white-cat-90296

08/19/2021, 10:29 AM
Hi there, I'm new here 👋 I was following the Pulumi API Gateway tutorial (this one https://www.pulumi.com/docs/tutorials/aws/rest-api/ ) and I was wondering what would be the best way for me to use external packages in the lambda function. Here:
{
            path: "/source",
            method: "GET",
            eventHandler: (req, ctx, cb) => {
                cb(undefined, {
                    statusCode: 200,
                    body: Buffer.from(JSON.stringify({ name: "AWS" }), "utf8").toString("base64"),
                    isBase64Encoded: true,
                    headers: { "content-type": "application/json" },
                })
            }
        }
If anybody has a good example for this, please share it with me. Thanks!
g

great-sunset-355

08/19/2021, 2:44 PM
So here is the problem: Each lambda runtime requires a different packaging technology. All packages require to end up in S3 bucket Lambda resource Requires S3 url There isn't any built-in functionality that can help you with that AFAIK. (similar to what serverless framework does) Feel free to browse examples and prove me wrong https://github.com/pulumi/examples/ So what you need to build yourself (CDK devs did that as well) is a functionality that enables you to package the lambda with all its dependencies and uploads it to S3. There are multiple ways to achieve this: 1) Build the package zip files and upload them to S3 before running pulumi in your pipeline 2) Maybe plugin https://www.pulumi.com/docs/intro/concepts/assets-archives/ But that won't let you store previous versions in S3 if that's what you want (it's basically doing this: https://registry.terraform.io/modules/nozaq/lambda-auto-package/aws/latest?tab=dependencies) 3) Build a custom provider that can do that for you - essentially replicate the behaviour of this: https://docs.aws.amazon.com/cdk/api/latest/docs/aws-lambda-python-readme.html
🙏 1
w

white-cat-90296

08/20/2021, 7:51 AM
Thank you for the detailed breakdown @great-sunset-355 - I appreciate it! 🙃
👍 1
m

miniature-musician-31262

08/21/2021, 3:55 PM
I would also ask what you mean by “external packages” — do you mean like a library from npm? (If so, the answer may be much simpler.)
g

great-sunset-355

08/22/2021, 7:36 AM
@miniature-musician-31262 I'm curious about your solution, how would you create a required
.zip
file for lambda in a repository that contains lambda functions with multiple runtime languages? The ultimate goal is to upload a
.zip
with all dependencies (or a portion if using Lambda Layers)
f

freezing-van-87649

09/16/2021, 9:42 PM
one option that’s might be considering is just using AWS SAM to create the lambda zips