Chaos Injection for AWS Lambda - chaos_lambda
chaos_lambda is a small library injecting chaos into AWS Lambda. It offers simple python decorators to do delay, exception and statusCode injection and a Class to add delay to any 3rd party dependencies called from your function. This allows to conduct small chaos engineering experiments for your serverless application in the AWS Cloud.
Support for Latency injection using delay
Support for Exception injection using exception_msg
Support for HTTP Error status code injection using error_code
Using for SSM Parameter Store to control the experiment using isEnabled
Support for adding rate of failure using rate. (Default rate = 1)
Per Lambda function injection control using Environment variable (CHAOS_PARAM)
Install
pip install chaos-lambda
Example
# function.py
import os
from chaos_lambda import inject_fault
# this should be set as a Lambda environment variable
os.environ['CHAOS_PARAM'] = 'chaoslambda.config'
@inject_fault
def handler(event, context):
return {
'statusCode': 200,
'body': 'Hello from Lambda!'
}
Considering a configuration as follows:
{
"fault_type": "exception",
"delay": 400,
"is_enabled": true,
"error_code": 404,
"exception_msg": "This is chaos",
"rate": 1
}
When excecuted, the Lambda function, e.g handler('foo', 'bar'), will produce the following result:
exception_msg from config chaos with a rate of 1
corrupting now
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/.../chaos_lambda.py", line 199, in wrapper
raise Exception(exception_msg)
Exception: This is chaos
Configuration
The configuration for the failure injection is stored in the AWS SSM Parameter Store and accessed at runtime by the get_config() function:
{
"fault_type": "exception",
"delay": 400,
"is_enabled": true,
"error_code": 404,
"exception_msg": "This is chaos",
"rate": 1
}
To store the above configuration into SSM using the AWS CLI do the following:
aws ssm put-parameter --name chaoslambda.config --type String --overwrite --value "{ "delay": 400, "is_enabled": true, "error_code": 404, "exception_msg": "This is chaos", "rate": 1, "fault_type": "exception"}" --region eu-west-1
AWS Lambda will need to have IAM access to SSM.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssm:DescribeParameters"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ssm:GetParameters",
"ssm:GetParameter"
],
"Resource": "arn:aws:ssm:eu-north-1:12345678910:parameter/chaoslambda.config"
}
]
}
Supported Decorators:
chaos_lambda currently supports the following faults:
latency - Add latency in the AWS Lambda execution
exception - Raise an exception during the AWS Lambda execution
status_code - force AWS Lambda to return a specific HTTP error code
More information:
Metadata
Release files for chaos-lambda 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chaos-lambda-0.3.tar.gz | 6.7 kB | Without provenance | Details for chaos-lambda-0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chaos_lambda-0.3-py3-none-any.whl | Python 3 | none | any | Details for chaos_lambda-0.3-py3-none-any.whl |
Total release size: 18.4 kB
Release files / chaos-lambda-0.3.tar.gz
| Download URL | chaos-lambda-0.3.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb9196f59604711aa55f23878200963cbb5881e940729bf39e03e0d23eeb1782
|
|
BLAKE2b-256 checksum How to use checksums |
3f873eac6aa9ca15a854288eb3c62b641220318da883b15eb70b08c49990354f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.8
|
Release files / chaos_lambda-0.3-py3-none-any.whl
| Download URL | chaos_lambda-0.3-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27f88bbb2c8e1017033eac3659b916a5f96c24133f684d4085a65407c1ad7fc1
|
|
BLAKE2b-256 checksum How to use checksums |
0a5d2839f70b809b2114422cbc5fa36861c411fd221f2ee5a63c0271a67c437c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.8
|
Security for chaos-lambda 0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.