Create an IAM Role to use with Amazon CloudWatch Agent

Create an IAM Role to use with Amazon CloudWatch Agent

In Step 1, aws sts get-caller-identity failed on your instance because it has no credentials. Accessing AWS resources requires permissions, so here we create an IAM role and attach the permissions the CloudWatch agent needs to publish custom metrics (like memory usage), plus the permissions needed to install the agent remotely through AWS Systems Manager — no SSH key or bastion host required, which keeps this lab free and simple. In Step 3 we’ll attach this role to the instance you already launched.

  1. Use the search bar and type IAM to open the IAM console.

Search for the IAM console

  1. In the left navigation pane, select Roles, then select Create role.

Open Roles and select Create role

  1. Under Trusted entity type, keep AWS service selected. For Service or use case, choose EC2, keep the EC2 use case selected, then select Next.

Select AWS service as trusted entity and EC2 as the use case

  1. Search for and check CloudWatchAgentServerPolicy — this lets the CloudWatch agent publish metrics and logs.

Search for and select CloudWatchAgentServerPolicy

  1. Search again and also check AmazonSSMManagedInstanceCore — this lets AWS Systems Manager install and run the CloudWatch agent on the instance remotely, so you don’t need SSH access. The counter at the top should now read Permissions policies (2/1275). Select Next.

Also select AmazonSSMManagedInstanceCore, bringing the total to 2 policies

  1. On the Name, review, and create page, enter:
    • Role name: EC2-CloudWatch-Agent-Role
    • Description: Allows EC2 instances to call AWS services on your behalf.

Enter the role name EC2-CloudWatch-Agent-Role and a description

  1. Scroll down and confirm the Permissions policy summary lists both AmazonSSMManagedInstanceCore and CloudWatchAgentServerPolicy. Tags are optional and can be skipped. Select Create role.

Review both attached policies and select Create role

The current IAM console no longer has a separate “Tags” step for role creation — tagging is optional and available directly on the final “Name, review, and create” page if you want to add cost-tracking tags.