My lambda uses requests. I have one package.zip file that works correctly when I deploy using cdk. I’ve tried multiple things to reproduce the package.zip I have. All of the ways I’ve tried fail. Once the lambda is deployed with my other attempts of recreating my package.zip, I get the error
"errorMessage": "Unable to import module 'lambdaHanlder': No module named 'requests'"
I use pip install --target=package -r requirements.txt
to create the package folder and then zip the files inside of that folder.
my requirements.txt file:
constructs>=10.0.0,<11.0.0
requests
Creation of lambda layer and lambda:
const lambdaLayer = new lambda.LayerVersion(this, 'layer', {
code: lambda.Code.fromAsset('package.zip'),
description: 'Libraries needed.'
});
const fn = new lambda.Function(this, 'function', {
runtime: lambda.Runtime.PYTHON_3_9,
code: lambda.Code.fromAsset('lib/lambda'),
handler: 'lambda.handler',
description: new Date().toString(),
layers: [lambdaLayer]
})
I’m working on creating the readme for my project and would like to be able to reproduce the pacakge.zip file that works. I have one package.zip file that allows my lambda to use requests, so I know this way can be done and works. I don’t know how I created the package.zip, besides some combination that I’ve been attempting.
I’ve used different python versions using pyenv. 3.7, 3.8, 3.9, 3.11, and 3.12. I’ve tried switching my node version too.
Matthew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.