You are currently viewing How To Add An EC2 Instance To AWS System Manager (SSM)

How To Add An EC2 Instance To AWS System Manager (SSM)

How To Add An EC2 Instance To AWS System Manager (SSM)

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed how to install AWS System Manager (SSM).

https://cloudaffaire.com/how-to-install-aws-system-manager-ssm-agent/

In this blog post, we will discuss how to add an AWS EC2 instance to AWS System Manager (SSM). In order to manage an AWS EC2 instance to SSM, you first have to add the instance to SSM by installing the SSM agent on the EC2 instance and adding the instance profile with proper policy for SSM to the EC2 instance. Once the EC2 instance is added to SSM, all the SSM capabilities like SSM session manager, patching, script execution, etc. will be available for your EC2 instance.

Note: You can also manage your on-premises server using AWS SSM hybrid setup where there are some additional steps that you have to perform that are not covered in this blog post.

How To Add An EC2 Instance To AWS System Manager (SSM):

Requirements:

  1. One IAM instance profile roles for Systems Manager.
  2. One EC2 instance with SSM Agent Installed and Instance profile for SSM attached.
  3. IAM service liked role for SSM (Optional, for additional features like inventory)

Step 1: Create A SSM Service Linked Role.

Step 2: Create An Instance Profile For SSM.

Step 3: Create An AWS EC2 Instance.

You can follow the below blog post to create the EC2 instance.

https://cloudaffaire.com/how-to-create-an-aws-ec2-instance-using-aws-cli/

Step 4: Install SSM Agent On The EC2 Instance.

You can follow the below blog post to install AWS SSM agent.

https://cloudaffaire.com/how-to-install-aws-system-manager-ssm-agent/

Note: If you are using AWS provided standard AMI, SSM comes pre-installed.

Step 5: Attach The Instance Profile Created In Step 2 To The EC2 Instance Created In Step 3.

Step 6: Get SSM Managed Instance Details.

Our EC2 instance has been successfully added to the SSM managed instance list. You can also confirm the same from the AWS SSM console.

How To Add An EC2 Instance To AWS System Manager (SSM)

Hope you have enjoyed this blog post, to get more details on AWS SSM, please refer below AWS documentation

https://docs.aws.amazon.com/systems-manager/index.html

 

This Post Has 2 Comments

  1. Avatar
    Danie de Jager

    aws iam add-role-to-instance-profile gives me a error
    bash: aws iam add-role-to-instance-profile: command not found
    the other commands is working.

  2. Avatar
    Danie de Jager

    I get this error:
    # aws iam add-role-to-instance-profile –instance-profile-name “AmazonSSMInstanceProfileForInstances” –role-name “AmazonSSMRoleForInstances”
    Traceback (most recent call last):
    File “/bin/aws”, line 27, in
    sys.exit(main())
    File “/bin/aws”, line 23, in main
    return awscli.clidriver.main()
    File “/usr/lib/python2.7/site-packages/awscli/clidriver.py”, line 69, in main
    rc = driver.main()
    File “/usr/lib/python2.7/site-packages/awscli/clidriver.py”, line 206, in main
    parsed_args, remaining = parser.parse_known_args(args)
    File “/usr/lib/python2.7/site-packages/awscli/argparser.py”, line 101, in parse_known_args
    parsed, remaining = super(CLIArgParser, self).parse_known_args(args, namespace)
    File “/usr/lib64/python2.7/argparse.py”, line 1737, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
    File “/usr/lib64/python2.7/argparse.py”, line 1778, in _parse_known_args
    option_tuple = self._parse_optional(arg_string)
    File “/usr/lib64/python2.7/argparse.py”, line 2086, in _parse_optional
    option_tuples = self._get_option_tuples(arg_string)
    File “/usr/lib64/python2.7/argparse.py”, line 2129, in _get_option_tuples
    if option_string.startswith(option_prefix):
    UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xc2 in position 23: ordinal not in range(128)

Leave a Reply