Alternative way of working Lambda layer in CDK
desawsume
Posted on August 3, 2022
What if your Lambda functions doesn't have the module or packages in AWS, and you wish to run this Lambda in the Cloud
Simple answer is using Lambda Layer.
CDK has the native way of handling it like below
layer = aws_lambda.LayerVersion(self, 'lambda-layer',
code = code,
layer_version_name='layer-bundle',
compatible_runtimes=[
aws_lambda.Runtime.PYTHON_3_7,
aws_lambda.Runtime.PYTHON_3_8,
aws_lambda.Runtime.PYTHON_3_9
]
)
The other way of do this is:
Deploy Python Lambda functions with .zip file archives.
- cd lambda
- python3 -m venv .venv-zip
- source .venv-zip/bin/activate
- pip install -r requirements.txt
- deactivate
- cd .venv-zip/lib/python3.9/site-packages
- zip -r ../../../../lambda_handler.zip .
- cd ../../../../
- zip -g lambda_handler.zip *.py requirements.txt
using the from_asset() method point to your zip file location
đź’– đź’Ş đź™… đźš©
desawsume
Posted on August 3, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
githubcopilot AI Innovations at Microsoft Ignite 2024 What You Need to Know (Part 2)
November 29, 2024