Interview Prep/AWS/EC2, Auto Scaling and Load Balancing

Session Manager: `An error occurred (TargetNotConnected) when calling the StartSession operation: i-0abc is not connected.`

IntermediateTroubleshootingEC2, Auto Scaling and Load Balancing
Answer

Likely causes → The SSM Agent is not registered. Common reasons: the instance profile does not have AmazonSSMManagedInstanceCore, the private subnet has no NAT or ssm, ssmmessages and ec2messages endpoints, the agent is stopped, or IMDS is disabled.

Diagnose →

aws ssm describe-instance-information --filters Key=InstanceIds,Values=i-0abc
aws ec2 describe-iam-instance-profile-associations --filters Name=instance-id,Values=i-0abc
aws ec2 describe-vpc-endpoints --filters Name=vpc-id,Values=vpc-0abc --query 'VpcEndpoints[].ServiceName'
# on the box via serial console:
sudo systemctl status amazon-ssm-agent; sudo tail /var/log/amazon/ssm/amazon-ssm-agent.log

Fix →

  1. Attach a role that has AmazonSSMManagedInstanceCore
  2. Add the three interface endpoints, with private DNS on and an SG that allows 443 from the instances
  3. Restart the agent, or turn on Default Host Management Configuration

Prevent → Bake the agent into AMIs and turn on Default Host Management Configuration across the organization.

aws All AWS questions Roadmap: AWS core services

More on EC2, Auto Scaling and Load Balancing