Closed imperialguy closed 8 months ago
I saw this issue because I was working on the same exact work. I just want to note that if you are building python packages for lambda, you have to install and zip up the packages on the same OS as lambda. If you do it on OSX for example, it will not have the proper header files to run in an AWS linux AMI for example.
The packages were zipped up on Amazon Linux 2 - the same that is used by lambda.
My customer is seeing the same: I use following code to zip dependencies which worked well for any other dependency like sqlalchemy, but it does not work for snowflake-sqlalchemy
cd ~/GitHub/[MYPROEJCT]/shared/AWS_Lambda_Layer
export lib=snowflake
export package=snowflake-sqlalchemy
export bucket=[MYBUCKET]
mkdir $lib
cd $lib
pip install $package --target ./.deployment
cd .deployment
zip -m -r $lib.zip .
copy zipped file to S3
aws s3 cp $lib.zip s3://$bucket/lambda-layer/
publish lambda layer
aws lambda publish-layer-version --layer-name $lib --content S3Bucket=$bucket,S3Key=lambda-layer/$lib.zip --compatible-runtimes python3.9 --compatible-architectures arm64
Then I add the snowflake layer to tested lambda function and it fails with following
When I don’t use layers and package snowflake-sqlalchemy dependencies during lambda deployment, it works well. When I use layers for sqlalchemy dependencies and package snowflake connector to the lambda, it works well and correctly picks up dependencies from layers.
I tried changing the order of merging as well as names of layers – none of that has effect on either functionality
This is a snippet of the dependencies
Any updates on this issue?
Exact same behavior as reported by @imperialguy when creating a Lambda Layer running on AWS Lambda Python3.8 runtime
It is working for me with lambda runtime Python3.9 if I build the layer inside a container using image public.ecr.aws/sam/build-python3.9:latest-x86_64.
I can confirm this is working with Python 3.9, I wasn't able to make it work with 3.8
marking this as closed as it seems to be resolved - if still further troubleshooting needed, do comment please and i can reopen
Please answer these questions before submitting your issue. Thanks!
What version of Python are you using (
python --version
)? 3.7 or 3.8What operating system and processor architecture are you using (
python -c 'import platform; print(platform.platform())'
)? AWS lambda amazon linux 2What are the component versions in the environment (
pip list
)?What did you do? Step 1: Install
snowflake-sqlalchemy
as an AWS lambda layer. Step 2: Create a sample lambda function with the following code. Add the above layer to it and run the function.What did you expect to see? I expect to see "hello world" and the AWS lambda function executed without any issue
What did you see instead?
Can you set logging to DEBUG and collect the logs? Not sure how the logging works on AWS lambda as per your below suggestion. I tried, but it didn't work.
for logger_name in ['snowflake.sqlalchemy', 'snowflake.connector', 'botocore']: logger = logging.getLogger(logger_name) logger.setLevel(logging.DEBUG) ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) ch.setFormatter(logging.Formatter('%(asctime)s - %(threadName)s %(filename)s:%(lineno)d - %(funcName)s() - %(levelname)s - %(message)s')) logger.addHandler(ch)