I pip installed aws-wsgi and flask using AWS Cloud9 and then downloaded the zip file.
This file was then uploaded to a Lambda Layer, which was then attached to my Lambda Function. However, I still get the following error:
{
"errorMessage": "Unable to import module 'lambda_function': No module named 'awsgi'",
"errorType": "Runtime.ImportModuleError",
"requestId": "81e04845-856a-4b98-85a4-7de4644e6244",
"stackTrace": []
}
I also get similar error for flask.
This is weird because I've imported requests, psycopg2-binary and other dependencies the same way. Only these 2 (awsgi & flask) are throwing errors.
Is there a different way to install these dependencies?
EDIT
STEPS how I created the layer (working on Windows):
- Logged into AWS Cloud9
- installed get-pip.py with the curl command:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python3 get-pip.pypython3 -m pip install flask aws-wsgi -t .- cd out of the directory named dependency
zip -r dependencies.zip dependency/- downloaded the zip file
- uploaded the zip file to Lambda Layers through AWS Lambda Console
Contents of the layer -> dependencies.zip
From the docs:
It means that you should have packaged your dependencies into a folder named
python(and notdependency)You can do that by doing this:
Create a file named
requirements.txtwith the list of your dependenciesRun these commands:
You don't have to do that on Cloud9. Any Python distribution (even Windows-based or Mac-based) will do.
The parameters mean:
--only-binary=:all:: don't compile any packages from source on the machine, only use binary distributions.--platform manylinux2014_x86_64: use the binaries targeting glibc-based distributions for x86_64 according to the table. Replacemanylinux2014_x86_64withmanylinux2014_aarch64if you are going to use your layer with ARM Lambdas.--target=python: put the dependencies into the subfolderpythonof the current folder (see above why)--implementation cp: only install dependencies runnable byCPython. That's the implementation that runs python code on Lambda runtime.--python-version 3.12: match the version of the runtime that will be running your lambdas.