I am trying to add the numpy package to my lambda function, but I can't import it.
I have followed several tutorials, but they all have the same problem. On my last attempt, I executed the following step by step:
When I run my lambda function without importing numpy, it works perfectly, however when I import it I get this error:
{
"errorMessage": "Unable to import module 'lambda_function': No module named 'numpy'",
"errorType": "Runtime.ImportModuleError",
"requestId": "0153834a-6b28-44d1-889f-3e2e3ead9c4a",
"stackTrace": []
}
A very common error on the forum, however everything is fine with lambda_function, because as I said it works fine if I'm not importing any module.
import json
import numpy
def lambda_handler(event, context):
# TODO implement
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
I would like to learn how to use Layers inside Lambda.
There are at least two ways to add NumPy to your AWS Lambda as layer:
AWS Layers and AWSSDKPandas-Python39 (Choose a layer accordingly for your Python version). Since Pandas is built on top of NumPy, you should be able to use NumPy once you add this Pandas layer.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With