snowflake-cloud-data-platformaws-lambda-layers

Lambda Layer Function for Snowflake


I have followed the standard method for creating a Lambda Layer in Snowflake.

[in a AWS EC2 instance] rm -rf snowflake mkdir -p snowflake/python/lib/python3.7/site-packages pip3 install --no-cache-dir --ignore-installed --upgrade snowflake-connector-python -t snowflake/python/lib/python3.7/site-packages cd snowflake; rm -f snowflake.zip; zip -r snowflake.zip .

I can create the Lambda Layer and then add it to my Lambda function. As well as validate that the library is attached, but when I call the Lambda function, it is failing on

import snowflake.connector

[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'snowflake'

Are there any snowflake Lambda libraries or detailed guides on what may be going wrong here. I build lambda layers all the time in this manner and usually the above process works.


Solution

  • The issue turned out to be a requirement on 3.7. I added the following to my library creation and it worked fine:

    I changed the default python version in my Lambda function to be 3.7 to match the python instance I used to compile the library, then I added the following into my code:

    ssh -i ${PEM_FILE} ${EC2_HOST} "cp -r snowflake/python/lib/python3.7/site-packages/* dblayer/python/lib/python3.7/site-packages"