pandas
is an open source library providing high-performance,
easy-to-use data structures and data analysis tools for the
Python
programming language. pandas
library is by
default not available in AWS Lambda Python environments. If you try to
import pandas
in aws lambda function, you will get below error.
import pandas
def lambda_handler(event, context):
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
# Output
Response
{
"errorMessage": "Unable to import module 'lambda_function': No module named 'pandas'",
"errorType": "Runtime.ImportModuleError",
"requestId": "a9dfd983-8cd6-4fe2-85c3-5e107ac230a4",
"stackTrace": []
}
For using pandas
library in Lambda function a
Lambda Layer
needs to attached to the Lambda function. This
tutorials lists the required steps for creating and attaching Lambda Layer
for pandas
module.
python3.9 -m venv test_venv
source test_venv/bin/activate
python --version
mkdir python
pandas
library in
python directory created in Step 4
pip install pandas -t python
zip -r pandas.zip python
import logging
import pandas as pd
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def lambda_handler(event, context):
logger.info(pd.__version__)
Category: AWS