You are currently viewing How To Execute A Command Using AWS SSM Run Command

How To Execute A Command Using AWS SSM Run Command

How To Execute A Command Using AWS SSM Run Command

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed AWS SSM documents and how to create one.

In this blog post, we will discuss how to execute a command using AWS SSM Run Command.

What Is Run Command In AWS System Manager (SSM):

AWS Systems Manager Run Command lets you remotely and securely manage the configuration of your managed instances. A managed instance is any EC2 instance or on-premises machine in your hybrid environment that has been configured for Systems Manager. Run Command enables you to automate common administrative tasks and perform ad hoc configuration changes at scale. You can use Run Command from the AWS console, the AWS Command Line Interface, AWS Tools for Windows PowerShell, or the AWS SDKs. Run Command is offered at no additional cost.

Administrators use Run Command to perform the following types of tasks on their managed instances: install or bootstrap applications, build a deployment pipeline, capture log files when an instance is terminated from an Auto Scaling group, and join instances to a Windows domain, to name a few.

How To Execute A Command Using AWS SSM Run Command:


AWS CLI installed and configured. You can follow the below blog post to install and configure AWS CLI.

Step 1: Create an EC2 SSM Managed Instance.

Step 2: Create a new SSM document to execute a command through SSM Run Command.

Note: You can also use the default AWS provided ‘AWS-RunShellScript’ to execute the command instead of creating a custom document of your own.

Step 3: Execute a command using SSM Run Command.

Step 4: Execute a script through SSM Run Command.

Step 5: Cleanup.

Hope you have enjoyed this blog post, to get more details on AWS SSM, please refer below AWS documentation


This Post Has One Comment

  1. Avatar

    Thanks for the write up. Perhaps a correction needed – RHS of AWS_SSM_RUN_COMMAND_ID actually returns a multi-line text output.. The 1st row 2nd column has the ID output – So this needs to be extracted and set.

    echo $AWS_SSM_RUN_COMMAND_ID | grep -i -w COMMAND | awk '{print $2}'

Leave a Reply