Struggling to Set Up EC2 with SSM Access from Scratch

April 25, 2025 4 answers
Asked by poppyseed
I'm at my wit's end here! I'm trying to create a basic EC2 instance in a private network with SSM access, starting from a completely empty VPC. I've done tons of research and tried multiple options but still can't get it to work. I've used both Amazon Linux 2023 and Amazon Linux 2 AMIs that should have SSM installed. I've also included user data at startup, created service endpoints for SSM, added the necessary security group rules for port 443, and assigned the SSMRole to the EC2's IAM role. Yet, I keep encountering the same error: "SSM agent is not online. The SSM agent was unable to connect to a system manager endpoint to register itself with the service." I've spent around 6 hours trying to fix this by deleting and re-trying different options. Does anyone have a simple CloudFormation template or advice that could help me resolve this?

Answers

codepage
It sounds like you might be missing an instance profile with the required SSM permissions. Make sure to assign the `AmazonSSMManagedInstanceCore` policy to your IAM role. There's a whole guide on this if you need it!

poppyseed: I swear I set that up, but Iโ€™ll double-check it again.

Reply to this answer
5Raincheck
You don't need a user data script for Amazon Linux 2 because the SSM agent should start automatically. Double-check your network settings, especially if your EC2 is in a private subnet. If you're not routing correctly, the SSM agent wonโ€™t be able to connect. Also, consider temporarily adding a public IP so you can debug directly by SSHing into your instance and checking the logs.

poppyseed: I did add a public IP, and that worked, but I still don't understand the routing issues. The documentation is overwhelming!

Reply to this answer
mild salsa
Ensure your instance has the proper IAM permissions, access to service endpoints through a NAT gateway, or VPC endpoints. And do make sure the AMI you selected has the SSM agent included.
Reply to this answer
radar.16
Your instance needs outbound internet access. If itโ€™s a single instance, assign it a public IP with no inbound rules. For more instances, look into using a NAT gateway to manage network traffic.

poppyseed: Yeah, that seems to be a critical missing piece. Thanks for clarifying!

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions