This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
schemaVersion: '0.3' | |
description: Execute CPU stress via Run Command | |
assumeRole: "{{AutomationAssumeRole}}" | |
parameters: | |
AutomationAssumeRole: | |
type: String | |
description: "The ARN of the role that allows Automation to perform the actions on your behalf." | |
default: '' | |
InstanceIds: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "1.0.0", | |
"title": "What is the impact of randomly terminating an instance in an AZ", | |
"description": "terminating EC2 instance at random should not impact my app from running", | |
"tags": ["ec2"], | |
"configuration": { | |
"aws_region": "eu-west-1" | |
}, | |
"steady-state-hypothesis": { | |
"title": "more than 0 instance in region", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import random | |
REGION = 'eu-west-1' | |
def stop_random_instance(az, tag_name, tag_value, region=REGION): | |
''' | |
>>> stop_random_instance(az="eu-west-1a", tag_name='chaos', tag_value="chaos-ready", region='eu-west-1') | |
['i-0ddce3c81bc836560'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
schemaVersion: '2.2' | |
description: Run a CPU stress on an instance | |
parameters: | |
duration: | |
type: String | |
description: 'Specify the duration - in seconds - of the CPU burn. (Required) ' | |
default: "60" | |
cpu: | |
type: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
import sys | |
import logging | |
import boto3 | |
import os | |
log = logging.getLogger() | |
log.setLevel(logging.DEBUG) | |
sys.path.insert(0, './vendor') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import random | |
def getconfig(key): | |
return { | |
'api-delay-services': ['ec2'], | |
'api-delay-range': [0, 3], | |
'api-delay-rate': 10, | |
'aws-fault-services': ['s3', 'dynamodb'], | |
'api-fault-rate': 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def corrupt_statuscode(func): | |
def wrapper(*args, **kwargs): | |
result = func(*args, **kwargs) | |
error_code, rate = get_config('error_code') | |
if not error_code: | |
return result | |
print("Error from config {0} at a rate of {1}".format(error_code, rate)) | |
# add injection approx rate% of the time | |
if random.random() <= rate: | |
print("corrupting now") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def corrupt_exception(func): | |
def wrapper(*args, **kwargs): | |
result = func(*args, **kwargs) | |
exception_msg, rate = get_config('exception_msg') | |
if not exception_msg: | |
return result | |
print("exception_msg from config {0} with a rate of {1}".format(exception_msg, rate)) | |
# add injection approx rate% of the time | |
if random.random() <= rate: | |
print("corrupting now") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def corrupt_delay(func): | |
def latency(*args, **kw): | |
delay, rate = get_config('delay') | |
if not delay: | |
return func(*args, **kw) | |
print("delay: {0}, rate: {1}".format(delay, rate)) | |
# if delay and rate exist, delaying with that value at that rate | |
start = time.time() | |
if delay > 0 and rate >= 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: ChaosInjectionLayer | |
frameworkVersion: ">=1.34.0 <2.0.0" | |
provider: | |
name: aws | |
layers: | |
latencyInjection: | |
path: ./ |