Operating EC2 with Systems Manager
Access, patch and configure fleets of instances without SSH keys or open ports using AWS Systems Manager.
Intermediate · about 3 hours · difficulty 2/5
Learn first: EC2 Instances, AMIs and Pricing Options, STS, Assume Role and Federation
Opening port 22 to the world and sharing .pem files on WhatsApp is how many first projects start. Production teams use AWS Systems Manager (SSM) instead.
Session Manager
- Shell access from the console or CLI with no inbound ports, no bastion host and no SSH keys.
- Access is controlled by IAM and every session can be logged to S3 or CloudWatch.
- Requirements: the SSM Agent (pre-installed on Amazon Linux and Ubuntu AMIs), an instance role with the AmazonSSMManagedInstanceCore policy, and outbound access to SSM (NAT or interface endpoints).
Other SSM capabilities
- Run Command: run a script across many instances at once.
- Patch Manager: schedule OS patching with maintenance windows.
- Parameter Store: store configuration and secure strings (covered again in the security section).
- Inventory and State Manager to track and enforce configuration.
Instance metadata
Instances can query http://169.254.169.254 for their ID, region and role credentials. Require IMDSv2 (session tokens) to block SSRF-based credential theft.
Azure Bastion with Azure Arc and GCP OS Login with IAP tunnelling solve the same problem on other clouds.
Pitfalls
- Instance role missing, so the instance never appears in Fleet Manager.
- Private subnets with no NAT and no SSM endpoints, so the agent cannot connect.
You are ready to move on when you can connect to a private instance with Session Manager, with no SSH key and no open inbound ports.
Key concepts
- Session Manager
- SSM Agent and instance role
- Run Command
- Patch Manager
- IMDSv2
- EC2 Instance Connect
Mini project
Launch a free-tier instance with no key pair and a security group with zero inbound rules. Attach an SSM role, connect with Session Manager, and use Run Command to install htop. Log sessions to a CloudWatch log group. Terminate the instance and delete the log group afterwards.
Check yourself
List the three things an EC2 instance needs before it shows up as a managed node in Systems Manager.
Free resources
- AWS Systems Manager documentation (AWS)
- Use IMDSv2 (AWS)