0

I have created a layer in aws for pandas, added this layer into my lambda function. but the code return an error Unable to import module 'lambda_function': No module named 'pandas'. what is the issue for this

My system is windows 11 and I am using python 3.9 and the following commands are used for creating zip file that contains pandas mkdir python cd python pip3 install pandas -t . Compress-Archive -Path . -DestinationPath pandas_layer.zip

1
  • Amazon provides AWS SDK for Pandas layers for you, which includes Pandas: aws-sdk-pandas.readthedocs.io/en/stable/layers.html The reason your layer isn't working is because there is a lot more to building a Pandas layer than just doing pip install, you have to include binary linked dependencies, which you can't do easily on a Windows machine. Commented Mar 5, 2024 at 13:45

1 Answer 1

-1

I've built the pandas layer for you. You can download it through this google drive link. This layer is for the x86_64 python3.11 runtime. If you don't trust my code, you can follow the steps here to build it yourself.

Test code:

import json
import pandas

def lambda_handler(event, context):
    # TODO implement
    print(f"pandas: {pandas.__version__}")
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

Test result:

Test Event Name
test

Response
{
  "statusCode": 200,
  "body": "\"Hello from Lambda!\""
}

Function Logs
START RequestId: 877b0199-a9f2-4b94-bec4-b6520ffdebfb Version: $LATEST
pandas: 2.2.1
END RequestId: 877b0199-a9f2-4b94-bec4-b6520ffdebfb
REPORT RequestId: 877b0199-a9f2-4b94-bec4-b6520ffdebfb  Duration: 2.22 ms   Billed Duration: 3 ms   Memory Size: 128 MB Max Memory Used: 119 MB Init Duration: 2196.50 ms

Request ID
877b0199-a9f2-4b94-bec4-b6520ffdebfb
Sign up to request clarification or add additional context in comments.

1 Comment

Not only pandas, I can't import any packages using layers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.