pulumi / pulumi-aws

An Amazon Web Services (AWS) Pulumi resource package, providing multi-language access to AWS
Apache License 2.0
459 stars 155 forks source link

lambda code inside folder named like the lambda function #671

Closed nickmeldrum closed 5 years ago

nickmeldrum commented 5 years ago

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?

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 various 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"),
lukehoban commented 5 years ago

my function code when deployed is wrapped in a folder with the same name as the generated lambda function name.

If I understand correctly - this is just part of how Lambda works - the function runs inside a folder named after the function.

Is there something else going on here that you believe is specific to Pulumi?

If so, a repro of that could help. Feel free to reopen

lukehoban commented 5 years ago

I can't work out what my handler should be as the folder name is generated?

Note that the folder name should not impact this at all - index.handler refers to the file and exported function. You should not have to guess the name.

nickmeldrum commented 5 years ago

Yes you are absolutely right thanks - I had got myself confused as to whether I was using the FileAsset/ AssetArchives correctly as when I invoked the lambda I got handler not found - but it was just because I had moved my lambda from TypeScript to JavaScript and forgotten to change my export line back from ES modules to commonjs!

On that subject by the way - any good examples/ tutorials explaining the subtleties of the various Asset classes and how they work?

Thanks for your response though!