Giter Site home page Giter Site logo

adhorn / aws-lambda-chaos-injection Goto Github PK

View Code? Open in Web Editor NEW
99.0 9.0 13.0 274 KB

Chaos Injection library for AWS Lambda

License: MIT License

Python 95.33% Makefile 2.37% Batchfile 2.30%
serveless chaos-engineering chaos-monkey aws lambda-functions amazon-web-services sre testing

aws-lambda-chaos-injection's Introduction

Chaos Injection for AWS Lambda - chaos_lambda

Documentation Status Issues Maintenance Pypi Travis Coveralls Twitter

chaos_lambda is a small library injecting chaos into AWS Lambda. It offers simple python decorators to do delay, exception and statusCode injection for your AWS Lambda function. This allows to conduct small chaos engineering experiments for your serverless application in the AWS Cloud.

  • Support for Latency injection using fault_type: latency
  • Support for Exception injection using fault_type: exception
  • Support for HTTP Error status code injection using fault_type: status_code
  • Using for SSM Parameter Store to control the experiment using is_enabled: true
  • 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 Faults:

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:

Full Documentation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.