Interview Prep/AWS/CloudFormation, CloudWatch, KMS, Secrets and Cost

A cross-account decrypt fails: `AccessDeniedException: The ciphertext refers to a customer master key that does not exist, does not exist in this region, or you are not allowed to access it.`

AdvancedTroubleshootingCloudFormation, CloudWatch, KMS, Secrets and Cost
Answer

Likely causes → One of three: (1) the key is in another Region, because KMS keys are Regional unless multi-Region, (2) the key policy in the owning account does not allow the caller's account or role, or (3) the caller's IAM policy has no kms:Decrypt on the key ARN. Cross-account access needs both the key policy and IAM. The error deliberately does not say which one failed.

Diagnose →

aws kms describe-key --key-id arn:aws:kms:us-east-1:222222222222:key/abcd... --query 'KeyMetadata.[Arn,KeyState,MultiRegion]'
aws kms get-key-policy --key-id <arn> --policy-name default --output text   # run in owning account
aws iam simulate-principal-policy --policy-source-arn <caller-role-arn> --action-names kms:Decrypt --resource-arns <key-arn>

Fix →

  1. Add a key policy statement allowing arn:aws:iam::111111111111:role/consumer to use kms:Decrypt and kms:DescribeKey
  2. Add a matching IAM allow on the consumer role, referencing the key ARN (not an alias)
  3. Call KMS in the key's Region, or use a multi-Region replica

Prevent → Template cross-account key grants, and use encryption context conditions to scope them.

aws All AWS questions Roadmap: Cloud cost & architecture

More on CloudFormation, CloudWatch, KMS, Secrets and Cost