Volatrade's opinionated Python3 lambda template
To use this template, just make a new repository on github.com, click the "Use Template" button, name your new function and you're ready to go!
Need this function to run every n minutes, hours, days or weeks? Use the following steps to get started
-
First, check your
serverless.ymland underfunction.<function-name>.eventsyou can change the schedule to the interval you want the job to run on.Any resource permissions that you'll need must be set within the iamRoleStatement
-
If you aren't running python3.7, install a python version manager such as pyenv
- You can create a python3.7 virtual environment using something like
pyenv virtualenv 3.7.9 <lambda-function-name> - Then you can run
pyenv local <lambda-function-name>to activate your virtual environment
- You can create a python3.7 virtual environment using something like
-
If you have to query a postgres db, read the section below on using psycopg2
-
Make sure you update create_env.sh to look like below, where all private keys should be mapped from this to circleci . These environment variables should exist in circleci.
cat > .env << EOF
SECRET_PASSWORD=${SECRET_PASSWORD}
SUPER_SECRET_HOST=${SUPER_SECRET_HOST}
-
The only way to run psycopg2 in an AWS Lambda environment is to use a custom built psycopg2 wrapper
-
When deploying, we clone the awslambda-psycopg2 repo amd move awslambda-psycopg2/psycopg2-3.7 to psycopg2 and move it to the root of the project to replace psycopg2 with this wrapper that enables it to run on AWS Lambda
-
For using psycopg2, reference the deploy script seen here.