1 Answer
- Newest
- Most votes
- Most comments
0
The concept of lambda layers will come into the picture only in AWS environment.
When you're testing locally, you can refer to the local package. However, you need to mention this package as external modules when bundling the lambda so that your lambda function will not bundle that package when deploying the lambda.
You would do something like this
const nodeJsFnProps: NodejsFunctionProps = {
bundling: {
externalModules: [
'aws-sdk', // Use the 'aws-sdk' available in the Lambda runtime
'date-fns',
],
},
runtime: Runtime.NODEJS_16_X,
timeout: Duration.minutes(3),
memorySize: 256,
};
const lambdaWithLayer = new NodejsFunction(this, 'lambdaWithLayer', {
entry: path.join(__dirname, '../src/lambdas', 'lambda.ts'),
...nodeJsFnProps,
functionName: 'lambdaWithLayer',
handler: 'handler',
layers: [logicLayer, utilsLayer],
});
I've written a detailed step-by-step guide on lambda layers here - https://www.cloudtechsimplified.com/aws-lambda-layers/
answered a year ago
Relevant content
- asked a year ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 4 months ago