Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Chaos Injection library for AWS Lambda

License

NotificationsYou must be signed in to change notification settings

adhorn/aws-lambda-chaos-injection

Repository files navigation

Documentation StatusIssuesMaintenancePypiTravisCoverallsTwitter

chaos_lambda is a small library injecting chaos intoAWS 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 applicationin theAWS Cloud.

  • Support for Latency injection usingfault_type: latency
  • Support for Exception injection usingfault_type: exception
  • Support for HTTP Error status code injection usingfault_type: status_code
  • Using for SSM Parameter Store to control the experiment usingis_enabled: true
  • Support for adding rate of failure usingrate. (Default rate = 1)
  • Per Lambda function injection control using Environment variable (CHAOS_PARAM)

Install

pip install chaos-lambda

Example

# function.pyimportosfromchaos_lambdaimportinject_fault# this should be set as a Lambda environment variableos.environ['CHAOS_PARAM']='chaoslambda.config'@inject_faultdefhandler(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.ghandler('foo', 'bar'), will produce the following result:

exception_msg from config chaos with a rate of 1corrupting nowTraceback (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 theAWS SSM Parameter Store and accessed at runtime by theget_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 theAWS 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 haveIAM 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

About

Chaos Injection library for AWS Lambda

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp