https://pulumi.com logo
Title
f

fresh-solstice-91936

12/14/2021, 11:33 PM
I'm trying to manually create an aws lambda function: index.ts:
const testLambda = new aws.lambda.Function("testLambda", {
  code: new pulumi.asset.AssetArchive({
    ".": new pulumi.asset.FileArchive("./handler"),
  }),
  role: iamForLambda.arn,
  handler: "handler.handler",
  runtime: "nodejs14.x",
  environment: {
    variables: {
      foo: "bar",
    },
  },
});
handler/handler.ts:
export const handler = () => {
  console.log("meow");
}
this fails with:
"errorType": "Runtime.ImportModuleError",
  "errorMessage": "Error: Cannot find module 'handler'\nRequire stack:\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
I'm sure I'm just referencing the handler wrong, but I've tried a few different things and can't figure it out lol.
g

green-stone-37839

12/14/2021, 11:36 PM
Has your typescript lambda function been compiled to js?
In other words, does handler.js exist in
./handler
?
f

fresh-solstice-91936

12/14/2021, 11:40 PM
Nope - it's typescript, and looking at the lambda payload it's ts there too
I'm guessing the node runtime doesn't speak typescript?
g

green-stone-37839

12/14/2021, 11:46 PM
Correct, your lambda function code needs to be compiled from ts to js, in order to execute in AWS.
f

fresh-solstice-91936

12/14/2021, 11:56 PM
lmao that fixed it, thanks!
I blame not touching the js ecosystem since pre-ts 😅