Skip to main content

SSM chaos by tag

AWS SSM chaos by tag induces chaos on AWS EC2 instances using the Amazon SSM Run Command.

  • It is executed using the SSM document that defines the actions which the systems manager can perform on your managed instances (that have SSM agent installed).
  • This SSM document is uploaded beforehand to AWS, whose name is referenced in the faults.
  • It helps execute custom chaos (like stress, network, disk or IO) on AWS EC2 instances for a specific duration using the given tag(s).

SSM chaos by tag

Use cases

AWS SSM chaos by tag:

  • Tests the resilience of an application that uses custom SSM document as input to execute chaos on EC2 instances.
  • Triggers the provided SSM document provided as an input to other AWS chaos.
  • After chaos, this fault cleans up the SSM document provided as an input to the EC2 instance.

Prerequisites

  • Kubernetes >= 1.17
  • The SSM document should be available in AWS.
  • EC2 service update and deployment concepts.
  • Authentication is done using IRSA or secret. For secret-based authentication, create a Kubernetes secret that has the AWS access configuration(key) in the CHAOS_NAMESPACE. Below is a sample secret file:
apiVersion: v1
kind: Secret
metadata:
name: cloud-secret
type: Opaque
stringData:
cloud_config.yml: |-
# Add the cloud AWS credentials respectively
[default]
aws_access_key_id = XXXXXXXXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXXX
tip

HCE recommends that you use the same secret name, that is, cloud-secret. Otherwise, you will need to update the AWS_SHARED_CREDENTIALS_FILE environment variable in the fault template with the new secret name and you won't be able to use the default health check probes.

Below is an example AWS policy to execute the fault.

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeInstances"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ssm:DescribeInstanceInformation",
"ssm:SendCommand",
"ssm:GetCommandInvocation",
"ssm:CancelCommand"
],
"Resource": "*"
}
]
}
note

Mandatory tunables

Tunable Description Notes
EC2_INSTANCE_TAG Instance tag of the target EC2 instance. Multiple tags can also be provided as a comma(,) separated values. Provide them as "key:value". For more information, go to EC2 instance tag.
REGION Region name of the target ECS cluster For example, us-east-1.

Optional tunables

Tunable Description Notes
TOTAL_CHAOS_DURATION Duration that you specify, through which chaos is injected into the target resource (in seconds). Default: 30s. For more information, go to duration of the chaos.
CHAOS_INTERVAL Interval between successive instance terminations (in seconds). Default: 30s. For more information, go to chaos interval.
AWS_SHARED_CREDENTIALS_FILE Path to the AWS secret credentials. Defaults to /tmp/cloud_config.yml.
DOCUMENT_NAME Name of the SSM docs that is added to AWS. Create or upload this document to AWS before providing the document as an input to any AWS chaos fault.
POLICY_NAME Specific policy used in an SSM document (or command), which defines the action to be executed on the target instances. You can provide multiple names as comma-separated values.
SEQUENCE It defines a sequence of chaos execution for multiple instances. Default: parallel. Supports serial and parallel. For more information, go to sequence of chaos execution.
INSTANCE_AFFECTED_PERC Percentage of total EC2 instances to target. Provide numeric values only. Defaults to 0 (corresponds to 1 instance). For more information, go to instance affected percentage.
RAMP_TIME Period to wait before and after injecting chaos (in seconds). For example, 30 s. For more information, go to ramp time.

SSM chaos by tag

Instance tag of the target EC2 instance. Multiple tags can also be provided as a comma-separated values. Provide them in the key:value format. Tune it by using the EC2_INSTANCE_TAG tag.

The following YAML snippet illustrates the use of this environment variable:

# target the EC2 instances with matching tag
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
chaosServiceAccount: litmus-admin
experiments:
- name: ssm-chaos-by-tag
spec:
components:
env:
# tag of the EC2 instance
- name: EC2_INSTANCE_TAG
value: 'key:value'
# region for the EC2 instance
- name: REGION
value: 'us-east-1'

SSM chaos by tag on multiple instances

Percentage of EC2 instances to target, based on the EC2_INSTANCE_TAG tag and REGION region. Tune it by using the INSTANCE_AFFECTED_PERC environment variable.

The following YAML snippet illustrates the use of this environment variable:

# percentage of EC2 instances, needs to terminate with provided tags
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
chaosServiceAccount: litmus-admin
experiments:
- name: ssm-chaos-by-tag
spec:
components:
env:
# percentage of EC2 instance filtered by tags
- name: INSTANCE_AFFECTED_PERC
value: '100'
# tag of the EC2 instance
- name: EC2_INSTANCE_TAG
value: 'key:value'
# region for the EC2 instance
- name: REGION
value: 'us-east-1'