https://pulumi.com logo
Title
e

elegant-pager-5412

04/27/2021, 12:15 PM
Hey guys! How can I configure a layer that will act as my
node_modules
? As mentioned in the docs: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path
m

millions-furniture-75402

04/27/2021, 1:22 PM
Something like:
const lambdaLayer = new aws.lambda.LayerVersion(`${appName}-lambda-layer`, {
  code: new pulumi.asset.FileArchive("./node_modules"),
  compatibleRuntimes: [aws.lambda.NodeJS12dXRuntime],
  layerName: `${appName}-lambda-layer`,
});
const lambdaFunctionApi = new aws.lambda.Function(
  `${appName}-api`,
  {
    code: new pulumi.asset.FileArchive("./dist/app"),
    handler: "app.handler",
    layers: [lambdaLayer.arn],
    role: applicationRole.arn,
    runtime: aws.lambda.NodeJS12dXRuntime,
  },
  { dependsOn: [applicationRole, lambdaLayer] },
);
Ideally in your build you would install only your production dependencies, e.g. if you’re using node:
npm install --prefix ${DESTFOLDER} --production