Lesson 1 of 3 Systems Manager Automation and Remediation

Automating Procedures with Systems Manager Runbooks

This lesson explains Systems Manager Automation runbooks, documents that describe a sequence of steps against AWS resources and managed nodes, which turn procedures into repeatable, auditable actions.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify AWS-provided runbooks.
  • Describe runbook structure and actions.
  • Grant Automation the permissions it needs.
  • Decide between predefined and custom runbooks.

AWS-provided runbooks

AWS publishes hundreds of runbooks, owned by Amazon and named with the prefixes AWS-, AWSSupport-, AWSConfigRemediation- and AWSEC2-. They cover common tasks such as restarting, stopping or resizing instances, creating AMIs and snapshots, enabling encryption, restricting security groups and troubleshooting connectivity. Using a predefined runbook is almost always the least-effort answer when one exists. The following table lists runbooks that appear frequently in operations scenarios.

RunbookPurpose
AWS-RestartEC2Instance / AWS-StopEC2InstanceRestart or stop instances
AWS-CreateImage / AWS-CreateSnapshotCreate an AMI or EBS snapshot
AWS-ResizeInstanceChange an instance type (stop, modify, start)
AWS-UpdateLinuxAmi / AWS-UpdateWindowsAmiPatch an AMI and create a new one
AWSSupport-TroubleshootSSH / AWSSupport-ExecuteEC2RescueDiagnose and repair unreachable instances
AWSSupport-TroubleshootManagedInstanceFind why a node is not managed by Systems Manager
AWS-DisablePublicAccessForSecurityGroupRemove open SSH and RDP rules
AWSConfigRemediation-EnableS3BucketEncryption and similarFix resources reported by AWS Config rules

Runbook structure

A runbook is a YAML or JSON document with schemaVersion: '0.3', an optional assumeRole, parameters and a list of mainSteps. Each step uses an action. The most important actions are aws:executeAwsApi (call any AWS API and capture outputs), aws:runCommand (run a Command document on nodes), aws:executeScript (run Python or PowerShell inline), aws:waitForAwsResourceProperty and aws:assertAwsResourceProperty (wait for or check a state), aws:branch (choose the next step), aws:approve (pause for human approval), aws:sleep, aws:invokeLambdaFunction, aws:executeAutomation (call another runbook) and aws:createImage. Steps have onFailure and maxAttempts settings, and outputs from one step can feed later steps.

schemaVersion: '0.3'
description: Snapshot the root volume, then restart the instance
assumeRole: '{{ AutomationAssumeRole }}'
parameters:
  InstanceId: {type: String}
  AutomationAssumeRole: {type: String}
mainSteps:
  - name: getRootVolume
    action: aws:executeAwsApi
    inputs:
      Service: ec2
      Api: DescribeInstances
      InstanceIds: ['{{ InstanceId }}']
    outputs:
      - Name: VolumeId
        Selector: $.Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId
        Type: String
  - name: snapshot
    action: aws:executeAwsApi
    inputs: {Service: ec2, Api: CreateSnapshot, VolumeId: '{{ getRootVolume.VolumeId }}'}
  - name: approve
    action: aws:approve
    inputs: {Approvers: ['arn:aws:iam::111122223333:role/OpsLead'], MinRequiredApprovals: 1}
  - name: restart
    action: aws:executeAutomation
    inputs: {DocumentName: AWS-RestartEC2Instance, RuntimeParameters: {InstanceId: ['{{ InstanceId }}']}}

The following diagram shows a runbook's steps and the settings around them.

The structure of an Automation runbook. A schemaVersion 0.3 document with an assumeRole and parameters runs mainSteps in order, each using an action such as aws:executeAwsApi, aws:waitForAwsResourceProperty, aws:branch or aws:approve. Outputs from one step feed later steps, and each step has onFailure and maxAttempts settings.
The step choices are illustrative.
Match the pairs

Runbook actions

Exam skills 1.2.3

Match each runbook action with what it does.

Log in to try this activity Interactive activities are free with an account.

Permissions for Automation

An Automation execution runs either with the permissions of the user who started it or with an assume role passed as the AutomationAssumeRole parameter. The assume role's trust policy must allow ssm.amazonaws.com, its permissions must cover every API the runbook calls, and the person or service starting the runbook needs iam:PassRole for it. Using an assume role lets operators run a tightly scoped procedure, such as restarting instances, without holding the underlying permissions themselves. EventBridge targets, Config remediation and State Manager associations always require an assume role.

Troubleshooting scenario

Runbook permission errors

Exam skills 1.2.3 · 4.1.2

Fix permission problems when runbooks run.

Log in to try this activity Interactive activities are free with an account.
Worked example

Choosing between predefined and custom

An operations team wants a one-click way to stop an unresponsive instance, take a snapshot of its volumes and start it again. No single AWS runbook does all three, but each step exists. A custom runbook with aws:executeAutomation steps calling AWS-StopEC2Instance, AWS-CreateSnapshot for each volume and AWS-StartEC2Instance reuses tested building blocks instead of reimplementing them in a script. The runbook is shared with the organisation's other accounts through document sharing.

Check yourself

Which runbook action pauses until a person approves?

Show answer

aws:approve.

Exam Tips

Remember for the exam

  • Prefer an AWS-provided runbook when one does the job.
  • aws:executeAwsApi calls any API; aws:runCommand runs commands on nodes; aws:approve waits for a human.
  • The assume role must trust ssm.amazonaws.com and the caller needs iam:PassRole.
  • Runbooks can call other runbooks with aws:executeAutomation.