- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud
Connecting to Managed Instances Using SSM Session Manager
AWS SSM Session Manager is an excellent feature to connect to and manage all your hybrid infrastructure remotely without having to use SSH for Linux or RDP for Windows instances. It provides the added bonus of security, as you don't need SSH/RDP ports open and access control to who can establish shell sessions using IAM policies. It also allows for logging and auditing of all activity during a shell session via Session Manager. In this hands-on lab, we'll configure an on-premises instance from scratch and access it using Session Manager as well as an EC2 instance within AWS.
Lab Info
Table of Contents
-
Challenge
Log in to the On-Premises VM and Install SSM Agent
-
Log in to the on-premises VM via SSH using the credentials provided:
ssh cloud_user<ON_PREMISES_VM_IP> -
Once you log in as
cloud_user, there should be a file namedssm_commands.txt. This file should have a list of commands for setting up SSM Agent and registering it with SSM. For now, we'll only install SSM Agent and enable it for starting up on boot:sudo yum -y install https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
-
-
Challenge
Log in to the Main SSM Command Node and Create a Hybrid Activation
-
In a new terminal, log in to the main SSM node spun up for you by the lab:
ssh cloud_user@<SSM_MAIN_NODE_IP>Once you log in as
cloud_user, there should be a file namedcreate_hybrid_activation.txt, which has commands for creating a hybrid activation, as well as some commands we'll use later. -
Create a hybrid activation:
aws ssm create-activation --default-instance-name MyOnPremInstance --iam-role SSMServiceRoleForActivation --registration-limit 1 -
The command above will return an
ActivationIDand anActivationCode. Copy them into a file to use in the next step.
-
-
Challenge
Register the On-Premises VM with SSM and Restart SSM Agent
-
On the CLI of the on-premises VM, register with SSM (using the
ActivationCodeandActivationIdfrom the previous step/task):sudo amazon-ssm-agent -register -code "<ActivationCode>" -id "<ActivationId>" -region us-east-1You should see logs confirming successful registration of your on-premises VM with SSM.
-
Restart SSM Agent:
sudo systemctl restart amazon-ssm-agent
Note: If for any reason the activation command fails, double-check your
ActivationIDandActivationCode, as well as internet connectivity of your on-premises VM outbound port443/HTTPS. Look in/var/log/amazon/ssm/amazon-ssm-agent.logfor further troubleshooting hints. -
-
Challenge
Find the On-Premises VM's Instance ID and Log In to the Instance
Log back in to the SSM Main node as
cloud_userand issue the following commands to find the newly registered on-premises VM's instance ID (which should start withmi) and log in to its shell using SSM API.-
Find the on-premises registered VM's instance ID using the SSM API:
aws ssm describe-instance-informationIn the output, you should only see one instance with the name
MyOnPremInstance. Copy itsInstanceIdfor the next command. -
Log in to the shell of the on-premises managed SSM instance using the Session Manager session API:
aws ssm start-session --target <ON_PREMISES_INSTANCE_ID>You're now logged in without using SSH.
-
-
Challenge
Connect to an SSM Managed Instance via the SSM Console
- Log in to the AWS Management Console with the credentials provided.
- Navigate to EC2 and verify you see the EC2 instance named
SSM-Setup-Via-GUI.- This instance already has SSM Agent installed.
-
Challenge
Create an IAM Role for EC2 Instance with SSM Policy
- Navigate to IAM.
- Go into Roles.
- Create a role and choose the AWS service EC2.
- Head to Permissions, type "SSM" in the policy search bar, and select the policy
AmazonEC2RoleforSSM. - Click Next, leave the tags as their default, and give your IAM role a name (e.g., "MyGUISSMRoleForEC2").
- In the EC2 console, select the
SSM-Setup-Via-GUIinstance, go into its instance settings, and select Attach/Replace IAM Role. - In the dropdown, select the
MyGUISSMRoleForEC2you just created and click Apply. - Reboot the EC2 instance
SSM-Setup-Via-GUI.
-
Challenge
Start a Session Manager Session with the Newly Created Instance
- Navigate to the Systems Manager console and select Session Manager in the left-hand menu.
- Click Start session. You might already see the on-premises instance we set up earlier in the lab. Wait a couple minutes for your newly configured
SSM-Setup-Via-GUIinstance to show up. - Once it does, select it, and click Start session. It should log you in to a browser-based shell session with your instance.
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.