This repository contains the AWS Lambda functions used in for ALPB Analytics Platorm, their associated tests, and some additional Python scripts used in the data pipeline.
Clone this repository and cd into the root directory.
Copy .env.example to .env and fill in the real values.
cdinto your function's directory.- Execute
$ python -m venv <my-virtual-env> - Activating your virtual environment - on Linux:
source my-virtual-env/bin/activate
On Windows:.\my-virtual-env\scripts\activate
Ensure your lambda function and its dependencies are organized like so:
functions/
└── <your-function_directory>/
└── venv/ # virtual environment
└── lambda_function.py
└── requirements.txt
Next:
cdinto thefunctionsdirectory.- Run the bash deployment script:
./deploy_lambda_py.sh -f <your_function_on_lambda>
Follow the instructions provided and your code should be deployed!
Note: since the bash script is primarily used to deploy API endpoints that interact with our database, the psycopg2 modules for Python 3.11 will be included in your deployment. Ensure your lambda function has the same runtime.
Ensure Docker engine is running on your machine, and cd into your function's directory (ex: /functions/process_trackman). You can check if your AWS CLI is configured properly by running $ aws sts get-caller-identity
- Run
$ cdk bootstrap aws://accountId/us-east-2. If you have already successfully run this command with the same account in the same region, you won't need to run it again. - Next, run
$ cdk deploy. If everything was successful, your image should be deployed to Lambda!
For more detailed instructions, check out this video.
For functions with fewer packages that don't require the Psycopg2 module, the AWS CLI is the most efficient method for deployment.
cdinto your function directory.
- Ensure your packages are present in the directory, either via Python virtual environment for by running
npm install.
- Run
zip -r <my-function>.zip .to zup up your function. - Run
aws lambda update-function-code --function-name <lambda-function-name> --zip-file fileb://<function-name>.zip.
Your lambda function should be updated now!