Hey, I'm having trouble creating a lambda layer co...
# help
j
Hey, I'm having trouble creating a lambda layer containing
aws-sdk
. I copied
node_modules/aws-sdk
, but now lambdas fail because of some other packages missing, which are dependencies of
aws-sdk
. I added the ones that I saw missing in error messages
jmespath
and
xml2js
to the layer, but now it's failing because of missing
xmlbuilder
, which is a dependency of
xml2js
... There must be a better way to do that! 🙃
This is how I create the layer folder
Copy code
#!/bin/bash

echo "Cleaning up workspace ..."
rm -rf .layers/aws-sdk

echo "Creating AWS SDK layer ..."
mkdir -p .layers/aws-sdk/nodejs/node_modules
cp -r node_modules/aws-sdk .layers/aws-sdk/nodejs/node_modules
cp -r node_modules/jmespath .layers/aws-sdk/nodejs/node_modules
cp -r node_modules/xml2js .layers/aws-sdk/nodejs/node_modules
cp -r node_modules/xmlbuilder .layers/aws-sdk/nodejs/node_modules

echo "AWS SDK layer is ready!"
and here's my layer config
Copy code
const defaultFunctionProps = {
      bundle: {
        externalModules: ['@prisma/client', '@shopcat/prisma', 'aws-sdk', 'aws-lambda'],
      },
      layers: [
        new lambda.LayerVersion(this, 'PrismaLayer', {
          code: lambda.Code.fromAsset('.layers/prisma'),
        }),
        new lambda.LayerVersion(this, 'AwsSdkLayer', {
          code: lambda.Code.fromAsset('.layers/aws-sdk'),
        }),
      ],
      permissions: ['sqs'],
    };
f
Hey @Jędrzej Kuryło, can you try npm installing
aws-sdk
into the
.layers/aws-sdk
folder? ie.
Copy code
// clear out everything in .layers/aws-sdk
cd .layers/aws-sdk
npm init -y
npm install --save aws-sdk
This way the node_modules should have all the dependencies of
aws-sdk
j
oh, didn't think of that 😅 I followed some examples I found online for prisma and adapted them for aws-sdk
thanks! i'll give it a try
seems obvious now 😅