I want to add my Amazon Lightsail instance to AWS Systems Manager.
Short description
Systems Manager isn't directly available for Lightsail instances.
You can use a hybrid activation to add your Lightsail instance to Systems Manager. To troubleshoot SSH connection issues, use Session Manager to access your Lightsail instance without SSH access. Session Manager is a capability of AWS Systems Manager.
Resolution
Generate a hybrid activation code and ID for Systems Manager
- Open the AWS Systems Manager console.
- In the navigation pane, under Node Management, choose Hybrid Activations.
- Choose Create activation. Use the following parameters:
Activation description: Enter a description.
Instance limit: Enter the number of instances that you want to register.
IAM role: Choose Create a system default command execution role that has the required permissions to automatically create a role that's named AmazonEC2RunCommandRoleForManagedInstances.
- Choose Create activation.
You receive a message similar to the following:
"You have successfully created a new activation. Your activation code is listed below. Copy this code and keep it in a safe place as you will not be able to access it again.
Activation Code byjELxxxxxxD0jmSP
Activation ID 1d7103ea-xxxxxxxxxxxxxxxx52258ac0b4
You can now install amazon-ssm-agent and manage your instance using Run Command."
Important: Note the Activation Code and Activation ID from the message that you receive.
Add a running Lightsail instance to Systems Manager
Use the following procedure if you have SSH access to the instance through the browser console or through an SSH client. If you don't have SSH access, then see the section Add a Lightsail instance to Systems Manager at launch.
To add a running Lightsail instance to Systems Manager, complete the following steps:
-
Log in to the Lightsail instance. Install the AWS Systems Manager Agent (SSM Agent):
sudo mkdir /tmp/ssm
sudo cd /tmp/ssm
wget https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb
sudo dpkg -i amazon-ssm-agent.deb
sudo systemctl restart amazon-ssm-agent
sudo systemctl enable amazon-ssm-agent
Note: These commands install SSM Agent on a Debian Lightsail instance. Bitnami-powered Lightsail instances use the Debian OS. To install other operating systems, see How to install the SSM Agent on hybrid Linux nodes.
-
Run the following command to register the instance to Systems Manager. Replace code with your activation code and id with your activation ID. Replace region with your AWS Region:
sudo amazon-ssm-agent -register -y -id '1d7xxxxxxxxxxxx1a52258ac0b4' -code 'byjELGxxxxxxx0jmSP' -region 'ap-south-1'
-
Run the following command to restart SSM Agent:
sudo systemctl restart amazon-ssm-agent
-
In the AWS Systems Manager console, choose Fleet Manager. Your Lightsail Instance appears with an ID that's prefixed with mi-.
-
Under SSM Agent ping status, verify that the instance is online. If the instance is online, then select the instance.
-
Choose Instance Actions, and then choose Start Session.
Add a Lightsail instance to Systems Manager at launch
If you experience SSH connection issues, then use the following procedure.
To add a Lightsail instance to Systems Manager when the instance launches, push the activation code through a user data script:
-
Take snapshot of the instance.
-
Launch a new Lightsail instance from the snapshot.
-
During the instance launch, choose Add launch script.
-
Add the following code to the Launch script field. Include the sudo amazon-ssm-agent -register command with your activation ID, activation code, and AWS Region:
sudo mkdir /tmp/ssm
sudo cd /tmp/ssm
wget https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb
sudo dpkg -i amazon-ssm-agent.deb
sudo systemctl enable amazon-ssm-agent
sudo amazon-ssm-agent -register -y -id '1d7xxxxxxxxxxxx1a52258ac0b4' -code 'byjELGxxxxxxx0jmSP' -region 'ap-south-1'
sudo systemctl restart amazon-ssm-agent
Note: These commands install the SSM Agent on a Debian Lightsail instance. Bitnami-powered Lightsail instances use the Debian OS. To install other operating systems, see How to install the SSM Agent on hybrid Linux nodes.
-
Complete the procedure in Add a running Lightsail instance to Systems Manager to access the instance from the AWS Systems Manager console.