Run Command executes a script on an instance. Automation runs a multi-step runbook that calls AWS APIs: stop an instance, snapshot it, create an AMI, rescue an unreachable box, wait for approval. This cheat sheet covers the commands you will use day to day and the errors you will hit.
Find a runbook
AWS publishes hundreds of runbooks with AWS-, AWSSupport- and AWSConfigRemediation- prefixes.
# AWS-owned Automation runbooks, names only
aws ssm list-documents \
--filters Key=Owner,Values=Amazon Key=DocumentType,Values=Automation \
--query 'DocumentIdentifiers[].Name' --output text | tr '\t' '\n' | sort
# Narrow by name
aws ssm list-documents \
--filters Key=Owner,Values=Amazon Key=DocumentType,Values=Automation Key=Name,Values=AWSSupport- \
--query 'DocumentIdentifiers[].Name' --output text
# Parameters a runbook expects
aws ssm describe-document --name AWS-CreateImage \
--query 'Document.Parameters[].[Name,Type,DefaultValue]' --output table
# Full content, to read what it actually does
aws ssm get-document --name AWS-CreateImage --document-format YAML --query Content --output text
Always read the content before you run an unfamiliar runbook in production. Some AWSSupport- runbooks stop the target instance.
Runbooks worth knowing
| Runbook | What it does | Key parameters |
|---|---|---|
AWS-RestartEC2Instance | Stops and starts instances | InstanceId |
AWS-StopEC2Instance / AWS-StartEC2Instance | Stop or start | InstanceId |
AWS-CreateImage | Creates an AMI | InstanceId, NoReboot |
AWS-CreateSnapshot | Snapshots one EBS volume | VolumeId, Description |
AWSSupport-ExecuteEC2Rescue | Detaches the root volume, repairs it on a helper instance, reattaches | UnreachableInstanceId |
AWSSupport-ResetAccess | Resets the Windows admin password or generates a new Linux SSH key | InstanceId |
Parameter names and behaviour can change between document versions. Confirm with describe-document before scripting.
Run against one resource
aws ssm start-automation-execution \
--document-name AWS-CreateImage \
--parameters InstanceId=i-0abc1234def567890,NoReboot=true
The command returns an AutomationExecutionId. Keep it.
Warning
AWS-CreateImagewithNoReboot=falsereboots the instance to get a consistent image.AWSSupport-ExecuteEC2Rescuestops the instance. Schedule these in a maintenance window.
Run across a fleet with rate control
Use --targets with --target-parameter-name to fan out. Automation starts one child execution per target.
aws ssm start-automation-execution \
--document-name AWS-RestartEC2Instance \
--target-parameter-name InstanceId \
--targets Key=tag:PatchGroup,Values=web-dev \
--max-concurrency 10% \
--max-errors 1
| Option | Meaning |
|---|---|
--targets Key=tag:<k>,Values=<v> | All resources with that tag |
--targets Key=ResourceGroup,Values=<name> | Members of a resource group |
--targets Key=ParameterValues,Values=i-1,i-2 | Explicit list |
--max-concurrency | Number or percentage running at once |
--max-errors | Stop starting new targets after this many failures |
Start with a small --max-concurrency and --max-errors 1 on anything that restarts instances. A tag that matches more than you expected is the most common way to cause an outage with Automation.
To see what a tag will match before running:
aws ec2 describe-instances \
--filters Name=tag:PatchGroup,Values=web-dev Name=instance-state-name,Values=running \
--query 'Reservations[].Instances[].[InstanceId,Tags[?Key==`Name`]|[0].Value]' --output table
Multi-account and multi-Region
From a delegated admin or management account, add --target-locations. Each target account needs the AWS-SystemsManager-AutomationExecutionRole (or the name you choose), and the admin account needs the AWS-SystemsManager-AutomationAdministrationRole.
aws ssm start-automation-execution \
--document-name AWS-RestartEC2Instance \
--target-parameter-name InstanceId \
--targets Key=tag:Env,Values=dev \
--target-locations '[{"Accounts":["111122223333","444455556666"],"Regions":["eu-west-1","us-east-1"],"TargetLocationMaxConcurrency":"1","TargetLocationMaxErrors":"1","ExecutionRoleName":"AWS-SystemsManager-AutomationExecutionRole"}]'
Watch and debug executions
ID=12345678-aaaa-bbbb-cccc-1234567890ab
# Overall status and failure message
aws ssm get-automation-execution --automation-execution-id "$ID" \
--query 'AutomationExecution.[AutomationExecutionStatus,FailureMessage]'
# Step-by-step: which step failed and why
aws ssm describe-automation-step-executions --automation-execution-id "$ID" \
--query 'StepExecutions[].[StepName,Action,StepStatus,FailureMessage]' --output table
# Recent failures in this Region
aws ssm describe-automation-executions \
--filters Key=ExecutionStatus,Values=Failed \
--query 'AutomationExecutionMetadataList[].[AutomationExecutionId,DocumentName,ExecutionStartTime]' \
--output table
# Child executions of a rate-controlled parent
aws ssm describe-automation-executions \
--filters Key=ParentExecutionId,Values="$ID" \
--query 'AutomationExecutionMetadataList[].[AutomationExecutionId,AutomationExecutionStatus,Target]' \
--output table
Statuses you will see include Pending, InProgress, Waiting, Success, TimedOut, Cancelled and Failed.
Common failures
| Message (key phrase) | Cause | Fix |
|---|---|---|
not authorized to perform on an EC2 API | The role running the runbook lacks the permission | Add it to the AutomationAssumeRole policy, or to your own identity if no assume role was given |
AssumeRole / unable to assume role | Trust policy doesn't allow ssm.amazonaws.com, or you lack iam:PassRole | Fix the trust policy; grant iam:PassRole on that role |
Step aws:runCommand timed out | Target isn't managed by SSM or the agent is offline | Check aws ssm describe-instance-information for the instance |
aws:waitForAwsResourceProperty timed out | Resource never reached the expected state | Look at the resource directly, e.g. an AMI stuck in pending |
Execution stuck in Waiting | An aws:approve step needs a decision | Approve or reject (below) |
Parent Failed but some targets succeeded | --max-errors reached | Read child executions, fix, rerun only failed targets |
Minimum trust policy for an Automation assume role:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "Service": "ssm.amazonaws.com" },
"Action": "sts:AssumeRole",
"Condition": { "StringEquals": { "aws:SourceAccount": "111122223333" } }
}]
}
Pass it with --parameters AutomationAssumeRole=arn:aws:iam::111122223333:role/ssm-automation, if the runbook declares that parameter.
Approvals, cancel and stop
# Approve or reject a waiting aws:approve step
aws ssm send-automation-signal --automation-execution-id "$ID" \
--signal-type Approve --payload Comment="CHG-4821 approved"
aws ssm send-automation-signal --automation-execution-id "$ID" --signal-type Reject
# Stop a running execution
aws ssm stop-automation-execution --automation-execution-id "$ID" --type Cancel
Caution
Cancelling stops further steps but does not undo completed ones. If a runbook has already stopped instances or detached volumes, check their state and finish or reverse the work by hand.
Prevent it next time
- Wrap production runbooks in a custom document that adds an
aws:approvestep and a dry-run listing of targets. - Use a dedicated
AutomationAssumeRoleper runbook family with least privilege, and restrict who caniam:PassRoleit. - Run fleet automations from a maintenance window or Change Manager so they are scheduled and recorded.
- Send execution status changes to EventBridge (
source: aws.ssm, detail typeEC2 Automation Execution Status-change Notification) and alert onFailedandTimedOut. Detail type names can vary; check a sample event in your account.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get