Question: How do I add a Lightsail instance to AWS Systems Manager?

I want to add my Amazon Lightsail instance to AWS Systems Manager. How do I do this?Short descriptionAWS Systems Manager isn't directly available for Lightsail instances. However, you can add your Lightsail instance to Systems Manager using a hybrid activation. You can also use AWS Systems Manager Session Manager to access your Lightsail instance without SSH access. This can be used to troubleshoot SSH connection issues.

ResolutionGenerate a hybrid activation code and ID for Systems Manager1.    Open the AWS Systems Manager console.2.    In the navigation pane, under Node Management choose Hybrid Activations.3.    Select Create activation, and then use the following parameters for the new hybrid activation:Activation description: Enter any description.Instance limit: Enter the number of instances you need to register using this code.IAM role: Choose Create a system default command execution role that has the required permissions. This automatically creates a role named AmazonEC2RunCommandRoleForManagedInstances.All other fields are optional.4.    Select Create activation. You receive a message similar to the following.Important: Record the Activation Code and Activation ID. Examples of these are shown in the following example:"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 byjELxxxxxxD0jmSPActivation ID 1d7103ea-xxxxxxxxxxxxxxxx52258ac0b4You can now install amazon-ssm-agent and manage your instance using Run Command."Add a running Lightsail instance to Systems ManagerNote: This method works when you have SSH access to the instance either through the browser console or through an SSH client such as PuTTY/terminal. If you don't have access, see the following section Adding a Lightsail instance to Systems Manager while launching.1.    Log in to the Lightsail instance and install the AWS Systems Manager Agent (SSM Agent). The following commands install the SSM Agent on a Debian Lightsail Instance. For installation instructions for other operating system versions, see Install SSM Agent for a hybrid environment (Linux).Note: Bitnami-powered Lightsail instances use the Debian operating system.sudo mkdir /tmp/ssmsudo cd /tmp/ssmwget https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.debsudo dpkg -i amazon-ssm-agent.debsudo systemctl restart amazon-ssm-agentsudo systemctl enable amazon-ssm-agent2.    After the installation completes, register the instance to Systems Manager using the following command, and then restart the agent. In the following example command, make sure to replace the activation code, ID, and Region.sudo amazon-ssm-agent -register -y -id '1d7xxxxxxxxxxxx1a52258ac0b4' -code 'byjELGxxxxxxx0jmSP' -region 'ap-south-1'sudo systemctl restart amazon-ssm-agent3.    On the AWS Systems Manager console, select Fleet Manager. Your Lightsail Instance appears with an ID that is prefixed with "mi-". Under SSM Agent ping status, verify that the instance is online.4.    If the instance is online, select the instance, select Instance Actions and choose Start Session. You can now access the instance as a normal managed instance.Adding a Lightsail instance to Systems Manager while launchingYou can use this method to an instance that's experiencing SSH connection issues. To troubleshoot an instance, first take snapshot of the instance, and then launch a new Lightsail instance from the snapshot.To add a Lightsail instance to Systems Manager when the instance launches, push the activation code using a user data script. This process is similar to adding user data when launching an Amazon Elastic Compute Cloud (Amazon EC2) instance.1.    While launching a new instance or launching an instance from a snapshot, select Add launch script.2.    Add the following code to the Launch script field. The following commands install the SSM Agent on a Debian Lightsail instance.For installation instructions for other operating system versions, see Install SSM Agent for a hybrid environment. Make sure to include the sudo amazon-ssm-agent -register command with the correct activation id, activation code, and Region in the launch script.Note: Bitnami-powered Lightsail instances use the Debian operating system.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-agent2.     After the instance launches, access it from the AWS Systems Manager console using the same steps as in the preceding section.