You launched the instance in Step 1 and created the IAM role in Step 2. Now we attach that role to the instance, so both the CloudWatch agent (Step 5) and AWS Systems Manager can use it — and so the aws sts get-caller-identity command that failed in Step 1 finally succeeds.
ec2-rightsizing-lab instance, then select Actions > Security > Modify IAM role.
EC2-CloudWatch-Agent-Role) from the dropdown, then select Update IAM role.
A reboot is not required — it typically takes under a minute for the instance metadata service to reflect the new role.
aws sts get-caller-identity

The AmazonSSMManagedInstanceCore policy in your role also lets AWS Systems Manager manage this instance — that’s what Step 5 relies on to install the CloudWatch agent with no SSH needed. Let’s confirm it registered.
System Manager to open the AWS Systems Manager console, making sure you’re still in the same Region as your instance.


If it’s not there after a few minutes, check in this order: the IAM role (Security tab on the instance must show AmazonSSMManagedInstanceCore attached), the instance’s public IP (Details tab — this should already be set from Step 1), the Region selector (must match between the EC2 and Systems Manager consoles), and finally, as a last resort, connect via EC2 Instance Connect and run sudo systemctl status amazon-ssm-agent to confirm the agent itself is running.
Having a public IP is not enough by itself — the instance’s subnet must also have a route table that sends internet-bound traffic to an Internet Gateway. If you check the SSM Agent log on the instance (sudo cat /var/log/amazon/ssm/amazon-ssm-agent.log) and see an error like the one below, it means the agent resolved the Systems Manager endpoint but couldn’t open a TCP connection to it — a routing problem, not a permissions problem:
SSM Agent unable to acquire credentials: <error>unexpected error getting instance profile role credentials
or calling UpdateInstanceInformation ... RequestError: send request failed
caused by: Post "https://ssm.<region>.amazonaws.com/": dial tcp <ip>:443: i/o timeout</error>
This shouldn’t happen if you launched in the default VPC as described in Step 1, since default VPCs come with an Internet Gateway and public route already configured. But if you used a custom VPC, here’s how to fix it:
0.0.0.0/0 pointing to a Target starting with igw- (an Internet Gateway). If instead the route table only has the local VPC route, that’s the problem — the subnet is actually a private subnet with no path to the internet.0.0.0.0/0, Target the Internet Gateway you just attached.Attaching an IAM role, calling the AWS CLI, and registering with Systems Manager are all free — none of this consumes Free Tier hours or generates a charge on their own.