Prerequisites:
- Install python locally (ex: 3.7.3).
- Create a Lambda function on AWS. Choose python 3.7 as Runtime and choose 'app.lambda_function.lambda_handler' as handler. Remember the name of your lambda, it will used in step 7.
- Create an event rule on AWS EventBridge as trigger. Ex of event schedule: cron(0/2 6-23 ? * * *)
- Create a variables.py file. Take variables_example.py as example.
Steps:
- Install a virtualenv lib via:
pip install virtualenv
- Navigate to the root of this project.
- Create a virtualenv (venv) via command:
virtualenv venv
- Activate the virtualenv:
linux:
source venv/bin/activate
win:
venv/Scripts/activate
- Install requirements.
pip install -r requirments.txt
- Prepare the deployment package for aws. Readme: https://docs.aws.amazon.com/lambda/latest/dg/python-package.html
In aws documentation they specify that you have to deactivate the venv.
deactivate
cd venv/lib/python3.7/site-packages
zip -r ../../../../my-deployment-package.zip .
- Deploy and Update. (whenever you update the code). Navigate to the root of the project and run the following commands:
zip -g my-deployment-package.zip app/__init__.py app/lambda_function.py app/variables.py
aws lambda update-function-code --function-name BikeCheckExample --zip-file fileb://my-deployment-package.zip