{"id":645,"date":"2025-03-05T05:25:37","date_gmt":"2025-03-05T05:25:37","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=645"},"modified":"2025-03-05T05:25:37","modified_gmt":"2025-03-05T05:25:37","slug":"aws-ssm","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=645","title":{"rendered":"How To Access A Private EC2 Instance Using AWS SSM?"},"content":{"rendered":"<p>In this blog, you will learn how to use the <a href=\"https:\/\/docs.aws.amazon.com\/systems-manager\/latest\/userguide\/what-is-systems-manager.html?ref=devopscube.com\" rel=\"noreferrer\"><strong>AWS SSM(Systems Manager<\/strong>)<\/a> session manager to access Private <a href=\"https:\/\/devopscube.com\/use-aws-cli-create-ec2-instance\/\" rel=\"noreferrer\">EC2 instances.<\/a><\/p>\n<p>AWS Systems Manager Session Manager is a feature that allows you to securely connect to your EC2 instances without needing a public subnet, public IP, or SSH access.<\/p>\n<h2 id=\"aws-systems-manager-workflow\">AWS Systems Manager Workflow<\/h2>\n<p>The following image shows the private EC2 access workflow using the AWS Systems Manager.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/ssm.png\" class=\"kg-image\" alt=\"The workflow diagram of the aws systems manager and private ec2 instance\" loading=\"lazy\" width=\"1920\" height=\"1080\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/ssm.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/ssm.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/ssm.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/ssm.png 1920w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Here is how the session manager works.<\/p>\n<ol>\n<li>The user initiates the SSM session from the local machine CLI. The local machine should have <a href=\"https:\/\/devopscube.com\/use-aws-cli-create-ec2-instance\/\" rel=\"noreferrer noopener\"><strong>AWS CLI<\/strong><\/a>  installed with <strong>Session Manager Plugin<\/strong>.<\/li>\n<li>The EC2 instance will have the SSM Agent inside it (most of the instances will have the agent by default, if not, need to install manually)<\/li>\n<li>The request will go to the AWS Systems Manager service first and inside the VPC (via VPC endpoints). The the SSM communicates with the SSM Agent present inside the instance.<\/li>\n<li>The EC2 instance sends session data to AWS Systems Manager, which then securely sends it to the local machine. This allows the user to access the EC2 instance without requiring a public IP address or an open SSH port.<\/li>\n<\/ol>\n<p>Now, let&#8217;s look at how to configure and set up Session Manager with a practical example.<\/p>\n<p>Follow the steps below, where we create a VPC from scratch and configure all the necessary network settings, IAM roles, and permissions for Session Manager to work from both the AWS Web Console and a user&#8217;s laptop using the AWS CLI.<\/p>\n<h2 id=\"step-1-create-a-vpc-with-private-subnets\">Step 1: Create a VPC with Private Subnets.<\/h2>\n<p>Navigate to the VPC console and click <code>Create VPC<\/code> the button to create a new VPC, if you already have a VPC, you can use that as well.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-138-1.png\" class=\"kg-image\" alt=\"the vpc creation for the ssm workflow\" loading=\"lazy\" width=\"1181\" height=\"311\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-138-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-138-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-138-1.png 1181w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>In the VPC creation page, choose the <code>VPC and more<\/code> option, which will help to create the required configurations in a simple manner.<\/p>\n<p>Give a name for the VPC and choose the VPC CIDR range, for now I have chosen the range of <code>10.0.0.0\/16<\/code><\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-139-1.png\" class=\"kg-image\" alt=\"selecting vpc name and the cidr value for the vpc creation\" loading=\"lazy\" width=\"728\" height=\"674\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-139-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-139-1.png 728w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Choose the required number of availability zones and public and private subnet counts.<\/p>\n<div class=\"kg-card kg-callout-card kg-callout-card-blue\">\n<div class=\"kg-callout-emoji\">\ud83d\udca1<\/div>\n<div class=\"kg-callout-text\">Here, you can see the NAT is enabled, but for SSM to work, NAT is not required, you can keep the value as <code spellcheck=\"false\" style=\"white-space: pre-wrap;\">None<\/code>.<\/p>\n<p>NAT will help the private network to access the internet without public IP<\/p><\/div>\n<\/div>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-140-1.png\" class=\"kg-image\" alt=\"chossing the number of private and public subnets and its availability zones\" loading=\"lazy\" width=\"729\" height=\"783\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-140-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-140-1.png 729w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>You can see the preview diagram on the right side section, which will help to understand the architecture.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-141-1.png\" class=\"kg-image\" alt=\"the vpc creation preview diagram from the aws console\" loading=\"lazy\" width=\"1415\" height=\"446\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-141-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-141-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-141-1.png 1415w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>The VPC creation will take a few minutes to complete.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-142-2.png\" class=\"kg-image\" alt=\"the vpc components creation list and the success message\" loading=\"lazy\" width=\"636\" height=\"722\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-142-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-142-2.png 636w\"><\/figure>\n<p>We have created two public and private subnets, but we are only going to use the private subnets.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-143-2.png\" class=\"kg-image\" alt=\"the list of created public and private subnets\" loading=\"lazy\" width=\"1246\" height=\"776\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-143-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-143-2.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-143-2.png 1246w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>For this demo, I will choose the first private subnet which is situated in the <code>us-west-2a<\/code> region, but you can choose any private subnet.<\/p>\n<p>Navigate to the <strong>Route tables<\/strong> of the VPC.<\/p>\n<p>On the <strong>Routes<\/strong> tab, we can see one rule, which only helps to route the traffic internally, and the other is the NAT gateway, which is for accessing internet from private instances.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-144-1.png\" class=\"kg-image\" alt=\"the routes of the private subnets \" loading=\"lazy\" width=\"1042\" height=\"668\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-144-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-144-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-144-1.png 1042w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>On the <strong>Subnet Associations<\/strong> tab, we can see that the two private subnets are associated.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-145-1.png\" class=\"kg-image\" alt=\"describing the private subnet route tables to see the subnet associations\" loading=\"lazy\" width=\"1015\" height=\"549\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-145-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-145-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-145-1.png 1015w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<h2 id=\"step-2-create-a-private-vpc-endpoint\">Step 2: Create a Private VPC Endpoint<\/h2>\n<p>Since we don&#8217;t have internet access but want to connect the AWS SSM service securely, we need <strong>Private VPC Endpoints<\/strong>.<\/p>\n<p>We are creating three endpoints:&nbsp;<strong>ssm<\/strong>,&nbsp;<strong>ssmmessages,<\/strong>&nbsp;and&nbsp;<strong>ec2messages<\/strong>.<\/p>\n<ol>\n<li><strong>SSM VPC Endpoint: <\/strong>Primary endpoint for the communication, which helps send the commands to the SSM.<\/li>\n<li><strong>SSM Messages VPC Endpoint:<\/strong> This is where you send and receive the communication output between SSM components such as the SSM Agent, Systems Service, etc.<\/li>\n<li><strong>EC2 Messages VPC Endpoint:<\/strong> Send and receive communication between EC2 and other AWS services.<\/li>\n<\/ol>\n<p>To create a VPC Endpoint, go to the&nbsp;VPC dashboard, navigate to the Endpoints, and click Create Endpoint.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-33-1.png\" class=\"kg-image\" alt=\"the vpc endpoint creation dashboard\" loading=\"lazy\" width=\"1009\" height=\"423\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-33-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-33-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-33-1.png 1009w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>In the Endpoint settings, provide an endpoint name and select the AWS services from the Service category.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-34-2.png\" class=\"kg-image\" alt=\"providing name and selectin the service type for the endpoint creation\" loading=\"lazy\" width=\"995\" height=\"687\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-34-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-34-2.png 995w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>In the <strong>Services<\/strong> section, select the service name <code>com.amazonaws.us-east-1.ssm<\/code> and select the VPC and the private subnets.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-35-4.png\" class=\"kg-image\" alt=\"select the service and network settings such as vpc and private subnets\" loading=\"lazy\" width=\"970\" height=\"691\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-35-4.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-35-4.png 970w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>In the <strong>Security Group<\/strong>s section, I am choosing the <strong>default<\/strong> one of the VPC Security groups.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-36-2.png\" class=\"kg-image\" alt=\"selecting the security group for the vpc endpoint creation\" loading=\"lazy\" width=\"966\" height=\"607\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-36-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-36-2.png 966w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>We have to create two more endpoints, same as above, one is <strong>SSM Messages.<\/strong><\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-37-1.png\" class=\"kg-image\" alt=\"the endpoint name for the second endpoint which is ssm messages endpoint\" loading=\"lazy\" width=\"979\" height=\"775\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-37-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-37-1.png 979w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>The third endpoint is for the <strong>EC2 Messages<\/strong> service.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-38-1.png\" class=\"kg-image\" alt=\"the third endpoint creation for the ec2 messages endpoint\" loading=\"lazy\" width=\"988\" height=\"824\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-38-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-38-1.png 988w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>The endpoint creation will take a few seconds to complete after we see the status as active and more details about it on the <strong>Details<\/strong> tab.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-39-1.png\" class=\"kg-image\" alt=\"the endpoints status and describing the more in-depth details\" loading=\"lazy\" width=\"1283\" height=\"868\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-39-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-39-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-39-1.png 1283w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<h2 id=\"step-3-default-security-group\">Step 3: Default Security Group<\/h2>\n<p>When creating a VPC, a Security group will also be created with a rule for internal routing.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-40-1.png\" class=\"kg-image\" alt=\"describing the default security group inbound rules to ensure the routes\" loading=\"lazy\" width=\"1296\" height=\"727\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-40-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-40-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-40-1.png 1296w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>We can see that only one rule is present in the inbound traffic, which is only for internal incoming traffic.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-41-1.png\" class=\"kg-image\" alt=\"describing the default security group outbound rules to ensure the routes\" loading=\"lazy\" width=\"1054\" height=\"710\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-41-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-41-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-41-1.png 1054w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>The outbound rule indicates that the traffic can go from the VPC to anywhere.<\/p>\n<h2 id=\"step-4-create-an-instance-profile-iam-role\">Step 4: Create an Instance Profile (IAM Role)<\/h2>\n<p>We need to create an instance profile for the private <strong>EC2 instance<\/strong>.<\/p>\n<p>We already have an <strong>AWS-managed IAM Policy<\/strong> <code>AmazonSSMManagedInstanceCore<\/code> for the instance profile with the required permissions.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-42-1.png\" class=\"kg-image\" alt=\"creating an instance profile for the ec2 instance to configure with the AWS SSM\" loading=\"lazy\" width=\"1296\" height=\"772\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-42-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-42-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-42-1.png 1296w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>We are creating an IAM Role with this IAM Policy <code>AmazonSSMManagedInstanceCore<\/code><\/p>\n<p>Select the <strong>Roles<\/strong> tab in the IAM Dashboard and click <strong>Create role<\/strong> to create a new one.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-43-1.png\" class=\"kg-image\" alt=\"creating role with the aws ssm role\" loading=\"lazy\" width=\"1277\" height=\"467\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-43-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-43-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-43-1.png 1277w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>On the next page,<\/p>\n<p>Choose the&nbsp;AWS service&nbsp;under the&nbsp;Trusted entity type.&nbsp;Under&nbsp;use case select EC2.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-44-1.png\" class=\"kg-image\" alt=\"selecting trust entity for the role to create instance profile\" loading=\"lazy\" width=\"1266\" height=\"866\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-44-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-44-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-44-1.png 1266w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>On the next page, we need to select the IAM Policy <code>AmazonSSMManagedInstanceCore<\/code> to attach with the IAM Role.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-45-3.png\" class=\"kg-image\" alt=\"selecting the ssm policy to attach with the instance profile\" loading=\"lazy\" width=\"1301\" height=\"513\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-45-3.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-45-3.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-45-3.png 1301w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>The next step is to provide a name to the Role and ensure the <strong>Trust Policy<\/strong> and the <strong>IAM Policy<\/strong> that we attach to the Role.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-46-3.png\" class=\"kg-image\" alt=\"providing name for the role and ensuring the trust policy of the role\" loading=\"lazy\" width=\"1283\" height=\"872\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-46-3.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-46-3.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-46-3.png 1283w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Now that the required IAM role is ready, we can check the configurations from the IAM console.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-47-1.png\" class=\"kg-image\" alt=\"describing the instance profile after creating it\" loading=\"lazy\" width=\"1284\" height=\"668\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-47-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-47-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-47-1.png 1284w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<h2 id=\"step-5-create-a-private-ec2-instance\">Step 5: Create a Private EC2 instance<\/h2>\n<p>We can create a private EC2 instance with the instance profile.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-48-1.png\" class=\"kg-image\" alt=\"creating a private instance to check the aws systems manager\" loading=\"lazy\" width=\"1297\" height=\"456\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-48-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-48-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-48-1.png 1297w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>I am creating an Amazon Linux instance for demo purposes, but you can choose any.<\/p>\n<p>The SSM Agent should be present in the instance, but most AWS instances come with it by default.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-49-1.png\" class=\"kg-image\" alt=\"providing name and selecting the instance type for the instance creation\" loading=\"lazy\" width=\"854\" height=\"763\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-49-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-49-1.png 854w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Please refer to the official <a href=\"https:\/\/docs.aws.amazon.com\/systems-manager\/latest\/userguide\/ami-preinstalled-agent.html?ref=devopscube.com\">documentation<\/a> to view the list of preinstalled SSM agent AMIs.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-50-2.png\" class=\"kg-image\" alt=\"selecting insrtance type and key for the instance creation\" loading=\"lazy\" width=\"844\" height=\"475\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-50-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-50-2.png 844w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>In the&nbsp;<strong>Network settings<\/strong>&nbsp;section, choose the correct VPC, private subnet, and security group.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-65-2.png\" class=\"kg-image\" alt=\"selecting the network configurations such as vpc, private subnet and security group\" loading=\"lazy\" width=\"838\" height=\"755\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-65-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-65-2.png 838w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p><!--kg-card-begin: html--><br \/>\n<span style=\"margin: 0px;padding: 0px\">In the&nbsp;<strong>Advanced details<\/strong>&nbsp;section, select the IAM Instance Profile that we created earlier.<\/span><br \/>\n<!--kg-card-end: html--><\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-67-1.png\" class=\"kg-image\" alt=\"in the advanced section, selecting the instance profile\" loading=\"lazy\" width=\"1639\" height=\"695\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-67-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-67-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-67-1.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-67-1.png 1639w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Wait until the instance state is running.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-68-2.png\" class=\"kg-image\" alt=\"describing the private instance to ensure the status \" loading=\"lazy\" width=\"1385\" height=\"665\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-68-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-68-2.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-68-2.png 1385w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<h2 id=\"step-aws-systems-manager-to-access-the-instance\">Step: AWS Systems Manager to access the Instance<\/h2>\n<p>After the EC2 instance creation is completed, it can be seen in the <strong>AWS Systems Manager<\/strong> dashboard under the <strong>Fleet Manager<\/strong> section.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-69-2.png\" class=\"kg-image\" alt=\"systems manager dashboard to see the registered ec2 instance\" loading=\"lazy\" width=\"2000\" height=\"672\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-69-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-69-2.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-69-2.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w2400\/2025\/03\/image-69-2.png 2400w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>We can get more detailed information if we click the Node ID.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-70-2.png\" class=\"kg-image\" alt=\"connecting the ec2 instance using the aws session manager from the systems manager dashboard\" loading=\"lazy\" width=\"1140\" height=\"722\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-70-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-70-2.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-70-2.png 1140w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>To connect the instance via SSM, we can use the Start terminal section from the Node actions or the Session Manager section of the EC2 instance<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-71-2.png\" class=\"kg-image\" alt=\"connecting the ec2 instance using the aws session manager from the ec2 dashboard\" loading=\"lazy\" width=\"2000\" height=\"749\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-71-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-71-2.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-71-2.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w2400\/2025\/03\/image-71-2.png 2400w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Now, we can access the instance without accessing the subnet from the internet.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-72-2.png\" class=\"kg-image\" alt=\"The access output of the ec2 instance via the systems manager\" loading=\"lazy\" width=\"1802\" height=\"1574\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-72-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-72-2.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-72-2.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-72-2.png 1802w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>We haven&#8217;t provided a key or even SSH access to this instance, so no other methods will work to connect with this private instance.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-91-3.png\" class=\"kg-image\" alt=\"ec2 instance connection method with the warning message\" loading=\"lazy\" width=\"658\" height=\"832\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-91-3.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-91-3.png 658w\"><\/figure>\n<p><!--kg-card-begin: html--><br \/>\n<span style=\"margin: 0px;padding: 0px\">We can see no public IP warning message in the EC2 Instance Connect method<\/span><br \/>\n<!--kg-card-end: html--><\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-92-3.png\" class=\"kg-image\" alt=\"ssh client connection method with the warning message\" loading=\"lazy\" width=\"837\" height=\"837\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-92-3.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-92-3.png 837w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>In the <strong>SSH client<\/strong> connect method, we can see the warning of the no key association.<\/p>\n<h2 id=\"how-do-we-configure-the-ssm-on-the-existing-ec2-instance\">How do we configure the SSM on the existing EC2 Instance?<\/h2>\n<p>If you already have a private EC2 instance but the instance profile was not attached when you created it, we can also attach the instance profile after the deployment.<\/p>\n<p>I have created another Private EC2 instance with no instance profile.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-93-3.png\" class=\"kg-image\" alt=\"list of ec2 instances in the ec2 dashboard\" loading=\"lazy\" width=\"1301\" height=\"862\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-93-3.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-93-3.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-93-3.png 1301w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>If we check the Session Manager section, we can&#8217;t able to connect the instance using the SSM.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-94-2.png\" class=\"kg-image\" alt=\"session manages section of the instance connection tab\" loading=\"lazy\" width=\"820\" height=\"664\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-94-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-94-2.png 820w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>We need to attach the instance profile with this existing Private EC2 instance.<\/p>\n<p>To attach the IAM Instance Profile to an existing cluster, in the instance dashboard, select <strong>Security<\/strong> in the <strong>Actions<\/strong> tab and select <strong>Modify IAM role<\/strong>.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-95-2.png\" class=\"kg-image\" alt=\"modifying the instance profile of the existing ec2 instance. \" loading=\"lazy\" width=\"1253\" height=\"869\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-95-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-95-2.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-95-2.png 1253w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>On the next page, select the Instance Profile we have already created and click the <strong>Update IAM role<\/strong> button.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-96-4.png\" class=\"kg-image\" alt=\"instance profile selection of the existing ec2 instance. \" loading=\"lazy\" width=\"819\" height=\"653\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-96-4.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-96-4.png 819w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>The associated Instance Profile will take a few minutes to update with the EC2 instance.<\/p>\n<p>After that, if you check the Session Manager tab of the connection dashboard, you will see the connect button.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-97-4.png\" class=\"kg-image\" alt=\"connecting an existing ec2 instance with the ssm instance profile. \" loading=\"lazy\" width=\"821\" height=\"587\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-97-4.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-97-4.png 821w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<h2 id=\"how-to-access-the-ec2-instance-using-aws-ssm-from-the-local-machine\">How to access the EC2 instance using AWS SSM from the local machine?<\/h2>\n<p>To access the instance from the local machine, need to install the SSM client.<\/p>\n<p>For Mac,<\/p>\n<pre><code>brew install session-manager-plugin<\/code><\/pre>\n<p>Once the installation is completed, we can connect the instance from the local machine via CLI.<\/p>\n<pre><code>aws ssm start-session --target &lt;INSTANCE_ID&gt; --region &lt;REGION&gt;<\/code><\/pre>\n<p>We can perform port forwarding if you have installed something in the private instance and want to access its dashboard from the local machine.<\/p>\n<p>For example, I have installed <a href=\"https:\/\/devopscube.com\/install-configure-prometheus-linux\/\">Prometheus<\/a> in a private EC2 instance, and need to access the dashboard from the local machine.<\/p>\n<p>To see the dashboard from the local machine by port forwarding, use the following command.<\/p>\n<pre><code>aws ssm start-session --target &lt;INSTANCE_ID&gt; --region &lt;REGION&gt; --document-name AWS-StartPortForwardingSession --parameters '{\"portNumber\":[\"9090\"],\"localPortNumber\":[\"9090\"]}'<\/code><\/pre>\n<p>The port number will be changed depending on the deployment inside the server.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-73-1.png\" class=\"kg-image\" alt=\"the aws ssm session created notification on terminal\" loading=\"lazy\" width=\"1745\" height=\"678\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-73-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-73-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-73-1.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-73-1.png 1745w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>To access the dashboard, open any browser from the local machine, and paste the URL <code>http:\/\/localhost:9090<\/code><\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-74-2.png\" class=\"kg-image\" alt=\"the prometheus dashboard \" loading=\"lazy\" width=\"2000\" height=\"1337\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-74-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-74-2.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-74-2.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-74-2.png 2178w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>We have explored only one use case of the AWS Systems Manager, but we can do various things that make it possible to use it as a secure configuration manager for the EC2 instances and for operation, application, and change management.<\/p>\n<p>Check all the options the SSM provides and utilize them for your needs.<\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/aws-ssm\/\" target=\"_blank\" rel=\"noopener noreferrer\">How To Access A Private EC2 Instance Using AWS SSM? \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/aws-ssm\/<\/p>\n","protected":false},"author":1,"featured_media":646,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-645","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=645"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/645\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/646"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}