
Automation documents: structure and types
An Automation document (a runbook) defines metadata and the workflow to execute. Typical top-level fields includeschemaVersion, description, parameters, and mainSteps. Documents live in the Systems Manager Documents section and can be invoked interactively or triggered by events.
Each
mainStep specifies the action type (for example, call an AWS API, run a script, or call another document) and its inputs. Use aws:runCommand, aws:executeAwsApi, aws:approve, and other built-in actions to build workflows.



Document actions and workflow controls
Automation supports multiple actions and control primitives to build robust runbooks:- API actions: call AWS APIs using
aws:executeAwsApi. - Run Command actions: run commands on managed instances with
aws:runCommand. - Script execution: run shell, PowerShell, or Python scripts.
- Control flow: branching, wait/sleep, and approvals for human-in-the-loop workflows.
- Error handling:
onFailureand conditional branching to rollback or notify.
- Branching — conditional
if/elsestyle logic to direct different paths. - Sleep/wait — insert delays between steps or poll for conditions.
- Approvals — pause the workflow until human approvers accept or reject.

Cross-account automation
SSM Automation supports centralized cross-account remediation. A central automation account can run a document that modifies security groups, patches instances, or applies network ACLs across member accounts. This requires the central account to assume a role in the target account with the necessary permissions.

- Systems Manager enforces an account-level limit on concurrent automation executions (for example, 100 concurrent executions). For very large scale remediation, implement throttling, batching, staging, or distribute executions across multiple accounts.
- Central automation typically: detect → assume target role → execute remediation → log results centrally.
Be aware of account-level concurrent execution limits when planning large-scale remediation. Throttle or stage executions to avoid hitting limits.
- AWS Config or an EventBridge rule detects a non-compliance or event.
- The event is routed to the central automation account.
- Central automation assumes an IAM role in the member account and performs remediation.
- Execution results are logged back to the central account for auditing.

- Consistent remediation logic across accounts.
- One document update applies everywhere.
- Unified audit trail and centralized logging.

Human-in-the-loop (approval) workflows
For high-risk operations (deleting production databases, opening security groups to the world, terminating production instances, or other irreversible changes), add an approval step inmainSteps before the risky action. The runbook will pause, notify approvers (for example via SNS), and continue only after the configured number of approvals. If approval is denied or times out, branch to rollback or notification steps.
A typical approval step:


Integration with EventBridge and AWS Config
A common and scalable pattern is to have AWS Config detect non-compliant resources and send a NON_COMPLIANT event to EventBridge. EventBridge then triggers an SSM Automation execution, passing contextual event data (resource IDs, account, region) into the runbook as parameters for targeted remediation.- Use EventBridge input transformers to map event fields into Automation
parameters. - Filter events at the rule level to reduce unnecessary executions and cost.

IAM and service trust requirements
IAM and service trust policies are central to successful Automation. Ensure the principals that start and run automations have required permissions and trust relationships.- Automation service role (used by Systems Manager during execution) must trust
ssm.amazonaws.com. - If EventBridge triggers automation, the EventBridge role must trust
events.amazonaws.comand have permissions to start automations. - The principal invoking automation requires
ssm:StartAutomationExecutionandssm:GetAutomationExecution. - If your automation assumes or passes roles, the principal must also have
iam:PassRole. - Instance profile roles used for Run Command must include
AmazonSSMManagedInstanceCoreor equivalent.


Always include
iam:PassRole for the principal that starts the automation if the Automation needs to assume or pass roles to other services. Missing iam:PassRole is a common cause of failures.Common automation use cases
Typical uses for SSM Automation:- Patch management and OS updates (scheduled or on-demand).
- Security remediation (close overly permissive security groups).
- Provisioning and lifecycle management (create/delete resources).
- Backup and snapshot orchestration.
- Incident response and configuration drift remediation.
Monitoring and troubleshooting
Use the Systems Manager console to view automation execution status and step-level details. Execution logs can be sent to CloudWatch Logs and S3, and correlated with EventBridge events or OpsCenter incidents. Execution statuses:

- Missing or insufficient IAM permissions (
ssm:*,iam:PassRole). - Target resources do not exist or are already in the desired state.
- API throttling and service rate limits.
- Long-running steps exceeding timeouts.
- Approval timeouts when approvers are unavailable.
- Inspect step-level output in the SSM console.
- Check CloudWatch Logs and S3 log archives for detailed output.
- Correlate EventBridge events and Config records to understand triggers.
- Re-run with increased logging or in a staging environment to reproduce.
Best practices
- Test and validate runbooks in non-production first.
- Use least-privilege IAM roles and scoped policies to reduce blast radius.
- Version-control documents and tag both documents and executions for traceability.
- Filter events at EventBridge rule level to avoid unnecessary executions and cost.
- Throttle, batch, or stage large-scale remediations to stay within concurrent execution limits.
- Persist execution logs to S3, build CloudWatch dashboards for trends, and track incidents in OpsCenter.

Links and references
- AWS Systems Manager Automation documentation: https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-automation.html
- EventBridge documentation: https://docs.aws.amazon.com/eventbridge/latest/userguide/what-is-amazon-eventbridge.html
- AWS Config documentation: https://docs.aws.amazon.com/config/latest/developerguide/what-is-aws-config.html
- IAM documentation: https://docs.aws.amazon.com/iam/latest/UserGuide/introduction.html
- Systems Manager Run Command and Managed Instance docs: https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-agent.html