Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
    • Security
Google Cloud Platform icon
Labs

Creating an SSM IAM Role and Configuring an EC2 Instance with AWS Systems Manager via the CLI

In this hands-on lab, we'll be dissecting the IAM role required by an EC2 instance to be able to communicate with the Systems Manager service. We'll first locate the managed AWS policy required for this role and create an EC2 instance via the command line, assigning it the instance profile (container for role assigned). Finally, we'll verify that Systems Manager (SSM) can detect the instance and communicate with it. (**Note:** This lab is focused on the AWS command line and all technical steps will be shown via the CLI.)

Google Cloud Platform icon
Lab platform
Lab Info
Level
Intermediate
Last updated
Sep 17, 2025
Duration
45m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Get the ARN of the SSM Policy for IAM Role AmazonEC2RoleforSSM
    1. Note down the ARN of the policy from the following command:

      aws iam list-policies --scope AWS --query "Policies[?PolicyName == 'AmazonSSMManagedInstanceCore']"
      
    2. Optionally, you may also use the following command, in addition to the value of DefaultVersionId from the above command, to look at the JSON document of the policy in question via the CLI:

      aws iam get-policy-version --policy-arn <ARN-OF-POLICY> --version-id <VERSION-ID-STRING-FROM-PREV-COMMAND>
      
  2. Challenge

    Create an IAM Role for EC2 and Assign the SSM Policy to It
    1. Copy the following JSON and create a new JSON file in your current directory. Name it EC2Trust.json:

      {
        "Version": "2012-10-17",
        "Statement": {
          "Effect": "Allow",
          "Principal": {"Service": "ec2.amazonaws.com"},
          "Action": "sts:AssumeRole"
        }
      }
      
    2. Create the role and attach the trust policy JSON file you created above to it. Make sure you execute the following command in the same directory where you created the EC2Trust.json file:

      aws iam create-role --role-name MyEC2SSMRole --assume-role-policy-document file://EC2Trust.json
      
    3. Assign the policy from the previous step to the newly created role:

      aws iam attach-role-policy --role-name MyEC2SSMRole --policy-arn <SSM-POLICY-ARN>
      
  3. Challenge

    Create and Attach an Instance Profile to the IAM EC2 Service Role
    1. Create an instance profile using the following command:

      aws iam create-instance-profile --instance-profile-name MyEC2InstanceProfile
      
    2. Copy the instance profile name (MyEC2InstanceProfile) and ARN in the output for later use when creating an EC2 instance.

    3. Add the role created in the second task to the instance profile created above:

      aws iam add-role-to-instance-profile --instance-profile-name MyEC2InstanceProfile --role-name MyEC2SSMRole
      
  4. Challenge

    Gather the Necessary Data to Plug Into the EC2 Instance Creation Command
    1. Get the subnet ID:

      aws ec2 describe-subnets --query "Subnets[?Tags[?Value == 'SubnetA'] ].SubnetId | [0]"
      
    2. Get the security group ID:

      aws ec2 describe-security-groups --filters Name=group-name,Values=SG --query "SecurityGroups[?GroupName == 'SG'].GroupId | [0]"
      
    3. Get the AMI ID (with SSM installed):

      aws ec2 describe-images --filters "Name=architecture,Values=x86_64" "Name=description,Values=*Amazon Linux 2023 AMI 2023.5.20240805.0 x86_64 HVM*" "Name=owner-id,Values=137112412989" "Name=image-type,Values=machine" --query "sort_by(Images, &CreationDate)[::-1].ImageId | [0]"
      
  5. Challenge

    Create an EC2 Instance Using Subnet, Security Group, and AMI 2 ID

    Plug in the subnet ID, security group ID, AMI 2 ID, and instance profile ARN in the following command:

    aws ec2 run-instances --associate-public-ip-address --security-group-ids <SECURITY-GROUP-ID> --iam-instance-profile Arn=<INSTANCE-PROFILE-ARN> --instance-type t2.micro --image-id <AMI-ID> --subnet-id <SUBNET-ID> --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=MyEC2}]"
    

    Note: We are giving our EC2 instance the name MyEC2 (basically we're tagging it with this name) so we can get its instance ID and later confirm that SSM sees it.
    If you gave your IAM instance profile the same name as given in the lab task (i.e., MyEC2InstanceProfile ) , you can fetch the instance profile ARN with the following command:

    aws iam get-instance-profile --instance-profile-name MyEC2InstanceProfile
    
  6. Challenge

    Confirm via SSM CLI API (or GUI) that the Newly Created EC2 Instance Is Visible to It
    1. Get the instance ID of the newly created instance (we named it MyEC2, so we'll use this name in the command to get its instance ID. If you tagged/named it differently, be sure to use that name):

      aws ec2 describe-instances --filters Name=tag:Name,Values=MyEC2 --query "Reservations[].Instances[].InstanceId"
      
    2. Run the following SSM instance information API command to see if the same instance ID from the command above is showing up in the SSM API's output, replacing <INSTANCE-ID> with your instance's ID:

      aws ssm describe-instance-information --query "InstanceInformationList[?InstanceId == '<INSTANCE-ID>']"
      

      The command should return an object with information about the newly configured EC2 instance with Systems Manager.

      Note: It can take up to 5 minutes for the instance to show up in the SSM GUI or API command output.

About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

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.

Get started with Pluralsight