Skip to content

Instantly share code, notes, and snippets.

View adhorn's full-sized avatar

Adrian Hornsby adhorn

View GitHub Profile
@adhorn
adhorn / chaos_lib.py
Created July 11, 2019 12:13
@corrupt_statuscode decorator
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")
@adhorn
adhorn / fault.py
Created July 24, 2019 16:04 — forked from kapilt/fault.py
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
@adhorn
adhorn / cpu-stress.yml
Last active August 19, 2019 14:06
CPU stress document for SSM
---
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
@adhorn
adhorn / stop-random-instance.py
Last active September 23, 2019 00:03
Example script to stop random ec2 instance in a particular AZ if that instance tag matches the input
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']
@adhorn
adhorn / stop-random-instance-exp.json
Last active October 31, 2019 07:00
Chaos Toolkit experiement to ramdomly stop instances in an AZ (here eu-west-1b)
{
"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",
@adhorn
adhorn / gist:4659eb98428c83726ad4ff2ea19a27f9
Created April 8, 2020 05:35
IAM role - SSM Run (Send) Command
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssm:DescribeAssociation",
"ssm:GetDeployablePatchSnapshotForInstance",
"ssm:GetDocument",
"ssm:DescribeDocument",
@adhorn
adhorn / gist:c315cb13331528b09f39a592344ec7cb
Created April 22, 2020 14:05
Chaos Toolkit experiment to stop docker locally
{
"version": "1.0.0",
"title": "What is the impact of an terminating the database master",
"description": "terminating the master database should not prevent the application from running",
"tags": ["db"],
"configuration": {
"endpoint_url": {
"type": "env",
"key": "ELEANOR_URL"
}
@adhorn
adhorn / gist:f8ef67bbadafae4abe53c8e650b21936
Created April 30, 2020 14:22
AWS SSM Automation example
---
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:
@adhorn
adhorn / stop_random_instance_api.yml
Created June 1, 2020 12:55
Randomly stop EC2 instances using SSM Automation
---
description: Stop instances in a particular AZ with tag filter
schemaVersion: '0.3'
assumeRole: "{{ AutomationAssumeRole }}"
parameters:
AvailabilityZone:
type: String
description: "(Required) The Availability Zone to impact"
TagName:
type: String
@adhorn
adhorn / stop_random_instance_api.py
Created June 9, 2020 14:34
Randomly stopping instance via AWS Lambda
import boto3
import random
import time
def stop_random_instance(ec2_client, az_name, tag):
paginator = ec2_client.get_paginator('describe_instances')
pages = paginator.paginate(
Filters=[
{