Hi all, I need some help setting up my lambda wit...
# getting-started
h
Hi all, I need some help setting up my lambda with Pulumi, nothing seems to work as expected from the docs. We're trying to migrate off SST I have a folder
handler/*
that houses all my lambda functions which all export handler
export const handler = () => {}
Here's an examples creating a lambda:
Copy code
const formatterLambda = new aws.lambda.Function(
    "payout-line-transformer",
    {
      name: "payout-line-transformer",
      runtime: aws.lambda.Runtime.NodeJS18dX,
      handler: "payout-line-transformer.handler",
      code: new pulumi.asset.AssetArchive({
        ".": new pulumi.asset.FileArchive(
          "./bin/handlers/payout-line-transformer.js",
        ),
      }),
      role: iamForLambda.arn,
    },
    { dependsOn: [iamForLambda] },
  );
This fails to create with error
Error: failed to register new resource payout-line-transformer [aws:lambda/function:Function]: 2 UNKNOWN: failed to compute archive hash for ".": './bin/handlers/payout-line-transformer.js' is neither a recognized archive type nor a directory
I understand that error, the problem is where I change the
code
to the below, all the files inside the handlers folder are packaged inside all the lambda
Copy code
code: new pulumi.asset.AssetArchive({
        ".": new pulumi.asset.FileArchive(
          "./bin/handlers",
        ),
I end up with something that looks like the attached screenshot, which is not what I want. I have not tried creating a .zip of a lambda, this is a bit strange to me coming from SST. My last question, is the package I install do not seem to be included in the lambda, somehow the "node_modules get left out". Everything works nicely in Pulumi except this lambda creating for me has been a bit weird. Any help will be appreciated 🙏 Thanks for the help.
d
For a single file, you'd need to use
FileAsset
, not
FileArchive
What version of the pulumi cli do you have installed? There was recently a regression around asset lookups, so can you make sure you're on the latest version
h
Thanks for the quick response, I'll give that a try. I'm using v3.112.0
d
3.112 should be fine