In this tutorial we will be creating a AWS Lambda Python Layer that will include the Python Requests package and we will compile the package with Docker and the LambCI image.
Getting Started
First we will create the directory where we will store the intermediate data:
1 2 |
|
Then we will create the directory structure, as you can see I will be using the python 3.8 runtime:
1 2 |
|
Write the dependencies to the requirements file:
1
|
|
Install dependencies locally using docker, where we will be using the lambci/lambda:build-python3.8
iamge and we are mounting our current working directory to /var/task
inside the container, and then we will be running the command pip install -r requirements.txt -t python/lib/python3.7/site-packages/; exit
inside the container, which will essentially dump the content to our working directory:
1 2 3 |
|
Zip up the deployment package that we will push to AWS Lambda Layers:
1
|
|
Publish the layer using the aws cli tools, by specifying the deployment package, the compatible runtime and a identifier:
1 2 3 4 5 |
|
Then when you want to reference the layer on the functio that you want to create, you can do it like this:
1 2 3 4 5 |
|
Thank You
Thanks for reading, if you like my content, check out my website, read my newsletter or follow me at @ruanbekker on Twitter.
Credit to oznetnerd.com.