This is a bash script I wrote to quickly create a python 3.7 layer on AWS.
The first part creates a zip file.
The trick to create a correct zip file for python lambda layers is to ensure the unzipped file has a directory structure like
python/lib/python3.7/site-packages/
and the actual package(s) is within site-packages folder. Otherwise lambda code gives an error like
{
"errorMessage": "Unable to import module 'lambda_function': No module named 'requests'",
"errorType": "Runtime.ImportModuleError"
}
Unfortunately, AWS documentation isn't very explicit about this.
The second part publishes the layer on to AWS using aws cli.
- This was created on a mac running python 3.7 but should work on linux also.
- AWS cli is installed and properly configured.
Line 29 gives this error which can be fixed by adding
mkdir python
just before 29.zip warning: name not matched: python