-
First, create your AWS account, set up AWS CLI and AWS SAM. AWS CLI is the command line interface to interact with Lambda and AWS SAM is the tool to test your Lambda functions locally without deploying. Check the Getting Started Documentation for more details.
-
Install python3 and virtualenv
-
Develop feature Check
main.py
file -
Create deployment package This is the .zip that will be pushed to Lambda and used by AWS SAM to test locally. To create the zip you can do something like:
# Zip the main file
zip -9r python_test.zip main.py
# Zip all the dependencies
cd lambda/lib/python3.6/site-packages
zip -9r ../../../../python_test.zip *
-
Create a SAM template This template will allow SAM to invoke your Lambda function locally
-
Test your function locally with SAM
$ echo '{"first_name": "Foo" }' | sam local invoke "IPGreeter"
- Upload to AWS Lambda
aws lambda create-function --region us-west-2 --function-name IPGreeter --zip-file fileb://python_test.zip --role arn:aws:iam::<your_account_id>:role/service-role/myTestRole --handler main.handler --runtime python3.6 --timeout 15 --memory-size 512
You may need to get the full path for your role. In order to do that, execute:
aws iam get-role --role-name myTestRole