Add External Python Libraries to AWS Lambda using Lambda Layers

We can utilize AWS CloudShell, a new AWS service that enables developers to interact with AWS resources programmatically without provisioning any servers. This service is ideal for our purposes. We will install our packages on CloudShell, zip them, and then upload them to an S3 bucket.



To begin, access the S3 console and create a new bucket with a unique name to store the zipped package. Remember to save the bucket name.

Next, access AWS CloudShell by clicking on the top-right of the console.

Once the terminal loads, create a directory called "packages" using the following commands in sequence:

mkdir packages
cd packages
python3 -m venv venv
source venv/bin/activate
mkdir python
cd python
pip install requests -t .
rm -rf *dist-info
cd ..
zip -r my-first-lambda-package.zip python
aws s3 cp my-first-lambda-package.zip s3://your-s3-bucket-name/

Post a Comment

Previous Post Next Post