Run Commands On An EC2 Instance With AWS Systems Manager
AWS Systems Manager provides configuration management, which helps you maintain consistent configuration of your Amazon EC2 or on-premises instances.
Published Mar 19, 2024
If you are a System administrator and assigned a task to upgrade the packages for one application running on an EC2 instance, but due to some security restrictions, you are not permitted to access production instances via SSH or bastion host. In this situation, you can use AWS Systems Manager to remotely run shell scripts or certain commands to update packages on EC2 instances.
In this blog, we will cover everything you need to know about AWS Systems Manager and how to use it!
- What is AWS System Manager and how does it work?
- Benefits of System Manager
- Who can use AWS Systems Manager?
- Hands-on – Run commands remotely on an EC2 Instance using AWS Systems Manager
- Conclusion

AWS Systems Manager provides its users visibility and control of their infrastructure on AWS. It has a unified user interface so one can view operational data from multiple AWS services and lets the user automate operational tasks across AWS resources.
- Quick problem detection
- Hybrid Environment Management
- Easy Automation
- Security and Compliance Maintenance
- Improve Visibility and Control
The key feature of System Manager is to make multiple roles can be performed easily. Hence, this service can be used by:
- System administrators
- Software developers
- Security architects
- Cloud architects
- IT professionals who would like to manage AWS resources.
In this a scenario wherein you are assigned tasks by your team to upgrade the packages for your application running on your EC2 instances. Due to some security restrictions, you are not permitted to directly access your production instances via SSH and are not even allowed to use the bastion hosts. In this situation let’s use Amazon Systems Manager to remotely run your shell scripts or certain commands to update packages on your EC2 instances.
- Step 1: Create an Identity and Access Management (IAM) role.
- Step 2: Create an EC2 instance.
- Step 3: Update the Systems Manager Agent.
- Step 4: Upgradation process via the Fleet Manager dashboard.
- Step 5: Run a Remote Shell Script.
Login to your AWS account on the AWS console and navigate to the IAM console to get started.
Click on “Roles” under the “Access management” section on the left navigation pane.

Click on “Create role” to create a new role. You will use this role to give Amazon Systems Manager permission to perform actions on your instances.

Search for the “AmazonEC2RoleForSSM” policy and click on the checkbox to add the policy to the role.

Once done, click on “Next: Review” and enter a name for the newly created role and description


Navigate to the Amazon EC2 console and ensure that the preferred region is selected in which you want to create your instance.




Note: Make sure the SSM agent is installed on your EC2 instance.







sudo systemctl status amazon-ssm-agent
"
Navigate to the Amazon Systems Manager console on AWS.

Click on “Fleet Manager” under the “Node Management” section in the left navigation pane.

To automate the upgradation, click on “Account Management” and then, click on “Auto-update SSM agent”.


Click on “Run Command” under the “Node Management” section in the left navigation pane.

Now, click on “Run command” to upgrade the SSM-agent manually.

Now, click on the radio button on the left of “AWS-UpdateSSMAgent”. This is known as the document and this will upgrade the Systems Management agent on the selected instance.






Now, to run a remote shell script for upgrading any packages on your EC2 instance, navigate back to the “Run Command” dashboard in Amazon Systems Manager and click on “Run Command”.

select the radio button on the left of “Choose instances manually” enter command parametes


Verify httpd package installed or not.

In this blog, we have explored that AWS Systems Manager has the ability to automate tasks and helps in keeping all our EC2 instances healthy, and applications managed, secure, and updated.