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

A new instance goes `pending` → `terminated` within seconds with state reason `Client.InternalError: Client error on launch`.

IntermediateTroubleshootingEC2, Auto Scaling and Load Balancing
Answer

Likely causes → Usually the EBS volumes are encrypted with a customer managed KMS key that the launching principal (or the ASG service-linked role) cannot use. It can also mean a snapshot is missing or the volume limit was exceeded.

Diagnose →

aws ec2 describe-instances --instance-ids i-0abc --query 'Reservations[].Instances[].StateReason'
aws ec2 describe-images --image-ids ami-0abc --query 'Images[].BlockDeviceMappings[].Ebs'
aws kms get-key-policy --key-id <key-id> --policy-name default

Fix →

  1. Allow the launching principal and AWSServiceRoleForAutoScaling to use the key: kms:CreateGrant, kms:Decrypt, kms:GenerateDataKeyWithoutPlaintext, kms:ReEncrypt* and kms:DescribeKey
  2. For cross-account AMIs, update the key policy in the owning account and create a grant for the service-linked role

Prevent → Keep a tested key-policy template for EBS keys that names the ASG service-linked role.

aws All AWS questions Roadmap: AWS core services

More on EC2, Auto Scaling and Load Balancing