15
loading...
This website collects cookies to deliver better user experience
pip
or pip3
. /requirements.txt
/python/
requirements.txt
is a file with the names of the packages we’re using, and python
is an empty folder which we will be installing dependencies into. See the Lambda layer documentation for more information on why we need to install into the python folder. /lambda_function.py
/lambda_layer/requirements.txt
/lambda_layer/python/
Remember, you need to run these commands in a Linux machine.
cd lambda_layer
pip install -r requirements.txt -t .python
zip -r ../app-name-depts-layer.zip *
app-name-depts-layer.zip
) which can be uploaded to AWS as a Layer. This zip file should have a python folder inside it, with the application dependencies installed from pip
inside.I recommend including the names of the packages that are included in the layer, as part of the description. This will be useful in the future, especially if you end up creating and using multiple layers.
lambda_function.py
import requests
def lambda_handler(event, context):
test_url = 'https://jsonplaceholder.typicode.com/todos/1'
response = requests.get(test_url)
return {
'statusCode': response.status_code,
'body': response.json()
}