Serverless Python Demo
This is a simple serverless application built in Python. It consists of an Amazon API Gateway backed by four AWS Lambda functions and an Amazon DynamoDB table for storage.
Requirements
- AWS CLI
- AWS SAM CLI for deploying to the cloud
- Python 3.9
- Artillery for load-testing the application
Deployment
Deploy the demo to your AWS account using AWS SAM.
sam build --use-container
sam deploy --guided
The command sam build --use-container
will first build and package the Lambda functions using docker.
sam deploy
will use AWS CloudFormation to deploy the resources to your account and output the API Gateway endpoint URL for future use in our load tests.
Load Test
Artillery is used to make 300 requests / second for 10 minutes to our API endpoints. You can run this with the following command.
cd load-test
./run-load-test.sh
This is a demanding load test, to change the rate alter the arrivalRate
value in load-test.yml
.
CloudWatch Logs Insights
Using this CloudWatch Logs Insights query you can analyse the latency of the requests made to the Lambda functions.
The query separates cold starts from other requests and then gives you p50, p90 and p99 percentiles.
filter @type="REPORT"
| fields greatest(@initDuration, 0) + @duration as duration, ispresent(@initDuration) as coldStart
| stats count(*) as count, min(duration) as min, pct(duration, 50) as p50, pct(duration, 90) as p90, pct(duration, 99) as p99, max(duration) as max by coldStart
coldStart | count | min | p50 | p90 | p99 | max |
---|---|---|---|---|---|---|
0 | 466633 | 3.48 | 8.2578 | 10.8157 | 18.8511 | 247.83 |
1 | 1092 | 672.05 | 715.3087 | 738.5569 | 763.3233 | 835.08 |
๐ With other languages
You can find implementations of this project in other languages here:
Security
See CONTRIBUTING for more information.
License
This library is licensed under the MIT-0 License. See the LICENSE file.