Running Automation at Scale Across Accounts and from Code
This lesson covers rate control, multi-account execution and starting runbooks from the CLI, SDKs and other services, so runbooks run consistently against many resources.
Learning outcomes
After completing this lesson, you will be able to:
- Control concurrency and error thresholds.
- Run runbooks across accounts and Regions.
- Start runbooks from code and other services.
Rate control
A runbook with a target parameter (such as InstanceId) can run against many resources selected by tag, resource group or parameter values. Concurrency limits how many targets are processed at once and the error threshold stops the execution when too many fail, both as numbers or percentages. This protects production: a bad change stops after a few failures instead of affecting the whole fleet.
The following diagram shows an execution stopped by its error threshold.

Rate control
Multiple accounts and Regions
Automation can run a runbook in several accounts and Regions from a central account. The central account needs the AWS-SystemsManager-AutomationAdministrationRole, and each target account needs the AWS-SystemsManager-AutomationExecutionRole trusted by the central account; both are usually deployed with CloudFormation StackSets. Targets are accounts or OUs plus Regions, with separate concurrency and error thresholds for locations. Runbooks can also be shared with specific accounts or the organisation.
The following diagram shows the roles in the central and target accounts.

Starting runbooks from code and services
Runbooks are started with the StartAutomationExecution API, so the CLI, any AWS SDK, a Lambda function or a script can run them. Executions can be monitored with GetAutomationExecution and are recorded in CloudTrail. Many services can start runbooks directly. The following table lists them.
| Trigger | How |
|---|---|
| EventBridge rule | Systems Manager Automation target with an IAM role |
| CloudWatch alarm | Through EventBridge, or an OpsItem whose suggested runbook an operator runs |
| AWS Config rule | Automatic or manual remediation action |
| Maintenance window | Automation task |
| State Manager | Association that runs a runbook on a schedule |
| Security Hub, OpsCenter | Custom action or OpsItem runbook |
| Any code | StartAutomationExecution API through an SDK or CLI |
# CLI: restart every instance tagged App=checkout, 2 at a time, stop after 1 failure
aws ssm start-automation-execution --document-name AWS-RestartEC2Instance \
--targets Key=tag:App,Values=checkout --target-parameter-name InstanceId \
--max-concurrency 2 --max-errors 1
# Python (boto3)
import boto3
ssm = boto3.client("ssm")
run = ssm.start_automation_execution(
DocumentName="AWS-CreateImage",
Parameters={"InstanceId": ["i-0123456789abcdef0"], "NoReboot": ["true"]})
print(ssm.get_automation_execution(AutomationExecutionId=run["AutomationExecutionId"])
["AutomationExecution"]["AutomationExecutionStatus"])How should the runbook start?
Weekly AMI backups across accounts
A company wants an AMI of every instance tagged Backup=weekly in 12 accounts and 2 Regions every Sunday. The administrator deploys the Automation administration and execution roles with StackSets, then creates a maintenance window in the central account with an Automation task that runs AWS-CreateImage against the tag across the target accounts and Regions, with 10% concurrency. AWS Backup would be the simpler choice for a pure backup requirement; Automation is chosen here because the team also runs pre-backup checks in the same runbook and deregisters AMIs older than eight weeks in a final step.
Which API starts a runbook from code?
Show answer
StartAutomationExecution.
Exam Tips
Remember for the exam
- Rate control: concurrency and error threshold limit the blast radius of a runbook.
- Multi-account Automation needs administration and execution roles, usually deployed with StackSets.
- Start runbooks from code with StartAutomationExecution.
- EventBridge, Config remediation, maintenance windows and State Manager can all run runbooks.