When authoring a Lambda function it may require dependencies which require building and deploying with the function or as a layer. This Serverless Application uses Lambda to build a Lambda Layer containing your dependencies removing the need for you to package them locally and upload them.
To prevent multiple Lambdas being created in accounts, I've created multiple version of the application for different python runtimes and architectures:
- python3-11-arm64-layer-builder - python3.11 arm64
- python3-11-x86-64-layer-builder - python3.11 x86_64
- python3-10-arm64-layer-builder - python3.10 arm64
- python3-10-x86-64-layer-builder - python3.10 x86_64
The Serverless Application can be installed using the console using the Serverless Application Repository.
- On the 'Public Applications' tab search for "layer-builder" (make sure you have the 'Show apps that create custom IAM roles or resource policies' tick box ticked) and then click on the application
- In the Lambda page that is opened under the 'Application Settings' section provide a name for the Layer that will be created and list the packages that you would like to be included in your layer (using the same format as pip. Make sure the 'I acknowledge that this app creates custom IAM roles.' tick box is ticked
- Click 'Deploy'
- You check progress of the deployment under the 'Deployment' tab of the window that is opened
- Once the deployment has finished you will be able to see the created Lambda Layer under the Layers section of the Lambda Console
To include the Serverless Application in your own SAM template.
- On the 'Public Applications' tab search for "layer-builder" (make sure you have the 'Show apps that create custom IAM roles or resource policies' tick box ticked) and then click on the application
- Click the 'Copy as Sam Resource' button in the top right of the page
- Paste the code into your SAM template
- Populate the two parameters:
- LayerName - the name of the Lambda Layer that will be generated
- LayerPackages - the packages that you would like to be included in your layer (using the same format as pip
- Make sure when you deploy your SAM template the parameter
--capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_IAM
is passed to the SAM CLI
In the samples folder is an example SAM and CloudFormation template which shows deploying the Serverless Application and using the generated Lambda Layer in a Lambda Function. Note the CloudFormation template still requires the transform for the AWS::ServerlessRepo::Application resource as there are no permissions for CloudFormation to access the resources outside of the Serverless Application Repository i.e. using a nested stack.
Please report any issues you find using in the GitHub repository issue tracker