This project creates two stacks. One stack creates a LambdaLayerVersion
that hold the NPM dependency chalk
. The other stack creates a new LambdaFunction
that uses the layer's chalk
dependency to print "Hello World!".
Notice: There are known CloudFormation limitations when using Lambda layers across multiple stacks. To workaround this problem, we create the Lambda layer stack first and store the created Lambda Layer's ARN in SSM parameter store. We then deploy the Lambda function stack which imports that Layer ARN from SSM parameter store. This allows users to update the configuration of the Lambda Layer without running into the dependency error:
Error: someResource cannot be updated as it is in use by otherResource
For other workarounds checkout this issue thread.
1. Install dependencies with Yarn v1
yarn install
2. Create the bootstrap stack in your AWS account This only needs to be ran once per account/region.
yarn bootstrap
3. Build Cloudformation files
yarn build
4. Deploy the Lambda Layer stack
yarn deploy LambdaLayerStack
5. Deploy the Lambda Function stack
yarn deploy LambdaFunctionStack