Search code examples
amazon-web-servicesaws-lambdapulumi

deploying lambda code inside a folder with an autogenerated name


I am trying to set up a lambda in pulumi-aws but my function code when deployed is wrapped in a folder with the same name as the generated lambda function name.

I would prefer not to have this as it's unnecessary, but more than that it means I can't work out what my handler should be as the folder name is generated?

(I realise I can probably use a reference to get this generated name, but I don't like the added complexity for no reason. I don't see a good reason for having this folder inside the lambda?)

E.g. my function code is 1 simple index.js file. with 1 named export of handler. I would expect my lambda handler to be index.handler.

(Note I am using TypeScript for my pulumi code but the Lambda is in JavaScript.)

I have tried a couple of options for the code property:

const addTimesheetEntryLambda = new aws.lambda.Function("add-timesheet-entry", {
    code: new pulumi.asset.AssetArchive({
        "index.js": new pulumi.asset.FileAsset('./lambdas/add-timesheet-entry/index.js'),
    }),

In this example the zip file was simply an index.js with no folder information in the zip.

const addTimesheetEntryLambda = new aws.lambda.Function("add-timesheet-entry", {
    code: new pulumi.asset.FileArchive("lambdatest.zip"),

Solution

  • AWS Lambda code is always in a "folder" named after the function name. Here is a Lambda that I created in the web console:

    AWS Lambda in AWS Console

    It doesn't affect the naming of the handler though. index.handler is just fine.