Learning center

Auto Scaling Client.InternalError on launch with encrypted volumes

An Auto Scaling launch that fails with Client.InternalError points at a KMS key the group's service-linked role cannot use for an encrypted EBS volume. AWS documents the full message, Client.InternalError: Client error on launch., for volumes under a customer managed key. The read that settles which of the nearby causes you have is a comparison: the group's ServiceLinkedRoleARN against the key policy and grants of the key that actually encrypts the volume.

What the message means#

The scaling activity fails with StatusMessage Client.InternalError: Client error on launch. AWS's explanation is specific: Auto Scaling tried to launch an instance with an encrypted EBS volume, and the service-linked role does not have access to the customer managed KMS key that encrypts it. On the EC2 side, the instance's state reason code Client.InternalError means a client error caused the instance to terminate during launch, which is why the instance appears and is gone within moments. Instance launch failures · StateReason

The service-linked role's predefined permissions include AWS managed keys and exclude customer managed keys, so a key that works when a person launches an instance directly can still fail for the group. AWS documents three causes, and each needs a different change: KMS key policy for encrypted volumes

  • The key is in the group's account, and its key policy grants no use to the service-linked role the group uses.
  • The key is in another account. A key policy that allows the group's account is not enough by itself; a grant from the group's account must name the service-linked role as grantee.
  • The key policy names a different service-linked role. A group can use the default AWSServiceRoleForAutoScaling or a role with a custom suffix, and a statement for one does not cover the other.

Find the failure and the role#

Use a read-only profile and replace the uppercase placeholders. The failed activities give the message and, in Description, the instance ID when one was created. describe-scaling-activities

aws autoscaling describe-scaling-activities \
  --profile PROFILE --region REGION --auto-scaling-group-name GROUP \
  --filters Name=Status,Values=Failed \
  --query 'Activities[].{start:StartTime,description:Description,message:StatusMessage}' \
  --output json --no-cli-pager

aws autoscaling describe-auto-scaling-groups \
  --profile PROFILE --region REGION --auto-scaling-group-names GROUP \
  --query 'AutoScalingGroups[0].{role:ServiceLinkedRoleARN,template:LaunchTemplate,mixedTemplate:MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification,overrides:MixedInstancesPolicy.LaunchTemplate.Overrides[].{type:InstanceType,template:LaunchTemplateSpecification}}' \
  --output json --no-cli-pager

role is the principal that must be able to use the key. template is the group's saved version, which is not always the version that failed. During an instance refresh, the replacements launch from the refresh's desired configuration, which the group adopts only after the refresh succeeds, so read DesiredConfiguration with describe-instance-refreshes as the refresh guide shows. If the group uses $Latest or $Default, resolve it to the number that was current at the failed activity's StartTime, as the launch template guide shows. An override that carries its own template launches its type from that template instead of the group's, so when the group lists such overrides, trace the template of each type that failed, or of each type in use when the failure does not name one. Use that template and version below. If the instance ID is still visible, its state reason confirms the EC2 side. EC2 shows recently terminated instances for a short interval, usually less than an hour. AutoScalingGroup fields · describe-instances

aws ec2 describe-instances \
  --profile PROFILE --region REGION --instance-ids INSTANCE_ID \
  --query 'Reservations[].Instances[].{id:InstanceId,state:State.Name,code:StateReason.Code,message:StateReason.Message}' \
  --output json --no-cli-pager

Find the key that encrypts the volume#

A volume can get its key from three places: a volume in the launch template, the snapshot behind the AMI's block device mapping, or the account's EBS encryption-by-default setting. Check all three, because a release that changed only the AMI can bring in a new key through its snapshots. KMS key policy for encrypted volumes

aws ec2 describe-launch-template-versions \
  --profile PROFILE --region REGION --launch-template-id TEMPLATE_ID --versions VERSION \
  --query 'LaunchTemplateVersions[].{image:LaunchTemplateData.ImageId,volumes:LaunchTemplateData.BlockDeviceMappings[].{device:DeviceName,encrypted:Ebs.Encrypted,key:Ebs.KmsKeyId,snapshot:Ebs.SnapshotId}}' \
  --output json --no-cli-pager

aws ec2 describe-images \
  --profile PROFILE --region REGION --image-ids AMI_ID \
  --query 'Images[].BlockDeviceMappings[].{device:DeviceName,snapshot:Ebs.SnapshotId,encrypted:Ebs.Encrypted}' \
  --output json --no-cli-pager

aws ec2 describe-snapshots \
  --profile PROFILE --region REGION --snapshot-ids SNAPSHOT_ID \
  --query 'Snapshots[].{id:SnapshotId,owner:OwnerId,encrypted:Encrypted,key:KmsKeyId}' \
  --output json --no-cli-pager

aws ec2 get-ebs-encryption-by-default \
  --profile PROFILE --region REGION --query 'EbsEncryptionByDefault' --output json --no-cli-pager

aws ec2 get-ebs-default-kms-key-id \
  --profile PROFILE --region REGION --query 'KmsKeyId' --output json --no-cli-pager

Then describe each candidate key. KeyManager AWS is an AWS managed key, which AWS says Auto Scaling can use without further authorization, so only CUSTOMER keys are suspects. The account in the key ARN tells you whether the key is local or cross-account. describe-key

aws kms describe-key \
  --profile PROFILE --region REGION --key-id KEY_ID \
  --query 'KeyMetadata.{arn:Arn,account:AWSAccountId,manager:KeyManager,state:KeyState}' \
  --output json --no-cli-pager

KeyState is worth recording too. This guide's sources do not say what a launch reports for a key that is disabled or pending deletion, so treat a state other than Enabled as a separate lead.

Compare the role with the policy and grants#

Read the key policy from the key's account; get-key-policy does not work across accounts, and default is the only policy name. List grants for the key and look for the group's role as grantee. get-key-policy · list-grants

aws kms get-key-policy \
  --profile KEY_ACCOUNT_PROFILE --region REGION --key-id KEY_ARN --policy-name default \
  --query 'Policy' --output text --no-cli-pager

aws kms list-grants \
  --profile KEY_ACCOUNT_PROFILE --region REGION --key-id KEY_ARN \
  --query 'Grants[].{grantee:GranteePrincipal,operations:Operations,constraints:Constraints,created:CreationDate}' \
  --output json --no-cli-pager
KeyPolicy names the group's roleGrant to the group's roleReading
Same accountNoNoAdd the two key policy statements for that role
Same accountNoYesCheck the grant's operations and constraints, and whether the role was recreated after the grant, before adding policy statements
Same accountNames the default role; the group uses a custom suffix, or the reverseNoPolicy for the wrong role; name the one in ServiceLinkedRoleARN
Other accountAllows the group's accountNoThe grant is missing
Other accountAllows the group's accountYesCheck the grant's operations, and whether the role was deleted and recreated after the grant

AWS's same-account policy has two statements for the service-linked role: one allowing kms:Encrypt, kms:Decrypt, kms:ReEncrypt*, kms:GenerateDataKey* and kms:DescribeKey, and one allowing kms:CreateGrant with the condition kms:GrantIsForAWSResource set to true. For a cross-account key, the key's account allows the group's account in its policy, and then an identity in the group's account creates a grant with the service-linked role as grantee principal. AWS warns that deleting and recreating the role after the grant leaves the grant unable to serve the group. KMS key policy for encrypted volumes · Service-linked roles

The third option AWS lists is to avoid the cross-account key: copy and re-encrypt the snapshot with a customer managed key in the group's account, then grant the role access to that key.

Two fictional outcomes#

The group orders-asg in account 111122223333 moves to launch template version 8, which adds an encrypted data volume. Every launch fails within seconds with Client.InternalError: Client error on launch., and the instances show state reason Client.InternalError.

In the first outcome the volume uses a key in 111122223333. Its policy names AWSServiceRoleForAutoScaling, but ServiceLinkedRoleARN on orders-asg is the custom role AWSServiceRoleForAutoScaling_orders. Adding the two statements for the custom role fixes launches without changing version 8.

In the second outcome the volume's snapshot is owned by a build account, 444455556666, and encrypted with that account's key. The key policy allows 111122223333, and list-grants shows no grant for the group's role. Creating the grant from 111122223333, or re-encrypting the snapshot with a local key, fixes launches.

Confirm on the replacement#

After the policy or grant change, the next launch activity should be Successful and the instance should reach InService. Check that the new instance's volumes are encrypted with the key whose policy or grant you changed, so the success is tied to that change. describe-volumes

aws ec2 describe-volumes \
  --profile PROFILE --region REGION --filters Name=attachment.instance-id,Values=INSTANCE_ID \
  --query 'Volumes[].{id:VolumeId,encrypted:Encrypted,key:KmsKeyId}' \
  --output json --no-cli-pager

Where this reading stops#

AWS's troubleshooting page lists only the KMS cause for this message, but the activity text does not name the key or the role. The comparison above is the evidence; the message only tells you where to look. A launch you run yourself uses your permissions and can succeed where the group fails. Groups that still use launch configurations to launch Spot Instances use a different role, AWSServiceRoleForEC2Spot, according to AWS's key policy page. For other launch-time signatures, see the signature table and launch template version failures.

Bring the key policy into code review#

The failing change and the fix often live in different repositories: a launch template or AMI pipeline in one, a key policy in another. Put the key ARN, the group's role and the failing activity in the pull request that changes the key policy or grant, so the reviewer can match the principal against the group. Proofline reviews GitHub pull requests; new organizations get one calendar month of hosted code review without a cloud connection. Start a free GitHub review · Eligibility and fair-use terms · Current product availability

Questions#

What does Client.InternalError: Client error on launch mean in EC2 Auto Scaling?

AWS documents it for a launch with an encrypted EBS volume whose customer managed KMS key the group's service-linked role cannot use. The instance terminates during launch, so the scaling activity fails within moments.

Which role needs access to the KMS key for an Auto Scaling group?

The service-linked role in the group's ServiceLinkedRoleARN, by default AWSServiceRoleForAutoScaling or a custom-suffix variant. The instance profile and the person who updated the group are different principals.

Why does a cross-account KMS key still fail after I allowed the account in the key policy?

AWS requires a grant in addition to the key policy for a key in another account. Create the grant from the group's account with the service-linked role as the grantee principal.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading