Skip to main content
In this lesson you’ll learn how to use AWS Systems Manager to run ad-hoc tasks with Run Command and to enforce a desired configuration continuously with State Manager. The workflow covers:
  • Creating an IAM role for EC2 so Systems Manager can manage the instance.
  • Launching an EC2 instance and attaching the IAM instance profile.
  • Running an ad-hoc command using Systems Manager Run Command.
  • Creating a State Manager association to keep the SSM Agent updated on a schedule.
Prerequisites (brief)
Before continuing, confirm the instance has the SSM Agent and either internet access or VPC endpoints for Systems Manager. Without network access or the correct IAM permissions, the instance will not appear as a managed node in Systems Manager.
If the instance does not appear in Systems Manager after launch, verify: the instance profile attached includes AmazonSSMManagedInstanceCore, the SSM Agent is running, and security groups/NACLs and routing allow access to Systems Manager endpoints (or you have configured VPC endpoints).

1) Create an EC2-managed IAM role for Systems Manager

Create an IAM role for EC2 and attach the managed policy AmazonSSMManagedInstanceCore. This policy grants the core permissions required for Systems Manager to manage the instance.
  • Console flow: IAM → Roles → Create role → Select EC2 as the trusted entity → Attach AmazonSSMManagedInstanceCore → Create.
  • Suggested role name: SSM-EC2-Role (remember this for the instance profile selection when launching EC2).
A screenshot of the AWS Identity and Access Management (IAM) Roles console showing a green confirmation banner "Role SSM-EC2-ROLE created" and a list of IAM roles (56) with search and create/delete buttons. The left sidebar shows IAM navigation items and the top bar displays the AWS account/organization.

2) Launch an EC2 instance and attach the role

When launching the EC2 instance, set the IAM instance profile to the role you created (for example, SSM-EC2-Role) in the Advanced Details section.
  • Choose an AMI (one that includes SSM Agent is recommended).
  • Choose an instance type (demo uses t3.micro).
  • In Advanced Details → IAM instance profile, choose SSM-EC2-Role.
  • Configure networking and security groups so the instance can reach Systems Manager endpoints (Internet Gateway/NAT or VPC endpoints).
  • Launch the instance and wait until its state is running.
A screenshot of the AWS EC2 console showing an instance launch in progress with a blue progress bar at 33% and the message "Creating security group rules." Below it is text asking the user to wait while the instance is launched.
Once the instance is running and the SSM Agent has connected, the instance will appear as a managed node in Systems Manager.

3) Use Run Command for an ad-hoc operation

Run Command is designed for one-off or interactive tasks across one or many managed instances. For example, use the AWS-UpdateSSMAgent document to update the SSM Agent immediately. Steps (console):
  • Systems Manager → Run Command.
  • Choose the document: AWS-UpdateSSMAgent.
  • Select targets: choose instances manually, by tags, or by resource group.
  • Configure parameters (defaults are usually fine for AWS-UpdateSSMAgent).
  • Execute and monitor command status.
Screenshot of the AWS Systems Manager "Run Command" console showing the Target selection screen, with the "Specify instance tags" option selected and fields for tag key and tag value. The page also shows alternatives to choose instances manually or by resource group.
After the command completes, refresh the Run Command page to view the execution results and per-target output. Run Command is best for immediate, ad-hoc operations where you need instant execution and feedback.
A screenshot of the AWS Systems Manager "Run Command" details page showing a Command ID (fc4a8a32-7287-4b21-...) and buttons to rerun or copy. The command status sections show Overall and Detailed status as "Success" with 1 target completed and 0 errors.
Quick checklist for Run Command:
  • Target(s) selected
  • Document chosen (e.g., AWS-UpdateSSMAgent)
  • Confirm parameters and run
  • Monitor status and view output per target

4) Use State Manager to enforce desired state on a schedule

State Manager applies a document (an association) to target instances on a schedule or continuously to ensure the desired state is enforced over time. This is ideal for recurring tasks such as keeping the SSM Agent updated across your fleet. Steps (console):
  • Systems Manager → State Manager → Create association.
  • Name the association (e.g., Demo-State-Manager).
  • Select the document: AWS-UpdateSSMAgent.
  • Provide parameters (defaults are typically fine).
  • Select targets (instances, tags, or all instances).
  • Optionally set an association execution role if State Manager needs cross-service permissions.
  • Configure a schedule: run once, manual, repeating interval, or a CRON expression.
  • (Optional) Configure concurrency, output to S3, severity, and alarms under Options.
A screenshot of the AWS Systems Manager console on the "Create association" page. The Parameters section is visible with fields for Version and an "Allow Downgrade" option set to false.
The schedule builder provides sensible defaults (for example a 30-minute interval) and supports custom CRON schedules to match your maintenance windows.
A screenshot of the AWS Systems Manager console on the "State Manager > Create association" page, showing the CRON schedule builder with the "Default" option (associations run every 30 minutes) selected. The left navigation and other scheduling options (Hourly, Daily) are also visible.
After creating the association you can view its status, last run time, errors, and initiate ad-hoc runs from the State Manager console. State Manager will re-apply the document to targets on the configured schedule to maintain the desired state.
A screenshot of the AWS Systems Manager console showing an association details page with Association ID 960167f3-4b6b-43c8-a524-0bc2805d49c8. The page shows the document name (AWS-UpdateSSMAgent), status (Success), and action buttons like "Apply association now," "Edit," and "Delete."

Run Command vs State Manager — when to use each

Summary

  • Use Run Command for immediate, on-demand tasks like updating the SSM Agent on specific instances.
  • Use State Manager to schedule recurring operations and to enforce a desired configuration across your instances.
  • Ensure instances have the SSM Agent, correct IAM instance profile (AmazonSSMManagedInstanceCore), and network access (Internet or VPC endpoints) so they are visible as managed nodes in Systems Manager.
Links and references

Watch Video