You are now going to create an AWS FIS experiment template. An experiment template contains one or more actions to run on specified targets during an experiment.
You may recall the configuration of the AWS Batch job definition, which specified 3 attempts inside the structure retryStrategy
. With this configuration in place, in case of job failure, AWS Batch will retry running that job twice more.
We are going to create an AWS FIS experiment template to send a interruption signal to up to 5 of the EC2 Spot instances. The instance selection is randomly chosen based on the presence of the tags that were set when creating the compute environment type : Spot
. If the EC2 instance is running an AWS Batch job, the job will exit and retry after other jobs finish or more EC2 capacity is dynamically added in response to the interruption signal.
Run the following command to generate the AWS Fault Injection Simulator (AWS FIS) experiment template file.
cat <<EoF > fis-experiment.json
{
"description": "SpotInterruption",
"targets": {
"SpotTags": {
"resourceType": "aws:ec2:spot-instance",
"resourceTags": {
"type": "Spot"
},
"filters": [
{
"path": "State.Name",
"values": [
"running"
]
}
],
"selectionMode": "COUNT(5)"
}
},
"actions": {
"Spot": {
"actionId": "aws:ec2:send-spot-instance-interruptions",
"parameters": {
"durationBeforeInterruption": "PT2M"
},
"targets": {
"SpotInstances": "SpotTags"
}
}
},
"stopConditions": [
{
"source": "none"
}
],
"roleArn": "${FISCustomRole}",
"tags": {}
}
EoF
Let’s explore the configuration parameters in the structure:
Execute this command to create the AWS FIS template from the JSON file defined above. To learn more about this API, see create-experiment-template CLI command reference.
export FIS_TEMPLATE=$(aws fis create-experiment-template --cli-input-json file://fis-experiment.json | jq -r '.experimentTemplate.id')
echo "FIS Template ID: ${FIS_TEMPLATE}"
Next, you are going to submit a rendering job request.