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

An app writes logs, but its CloudWatch log group stays empty.

IntermediateTroubleshootingCloudFormation, CloudWatch, KMS, Secrets and Cost
Answer

Likely causes → The role cannot write logs (logs:CreateLogStream, logs:PutLogEvents, or logs:CreateLogGroup if the group does not exist). The log group is KMS-encrypted and the key policy does not allow the logs.<region>.amazonaws.com principal. Or you are looking in the wrong Region or group name.

Diagnose →

aws logs describe-log-groups --log-group-name-prefix /aws/lambda/orders --query 'logGroups[].[logGroupName,kmsKeyId]'
aws logs describe-log-streams --log-group-name /aws/lambda/orders --order-by LastEventTime --descending --max-items 3
aws iam list-attached-role-policies --role-name orders-lambda-role

Fix →

  1. For Lambda, attach AWSLambdaBasicExecutionRole. For ECS, give the execution role logs:* on the group
  2. Create the group in IaC with retention set
  3. Fix the KMS key policy for CloudWatch Logs

Prevent → Pre-create every log group with retention and permissions, rather than relying on auto-create, which also means infinite retention.

aws All AWS questions Roadmap: Cloud cost & architecture

More on CloudFormation, CloudWatch, KMS, Secrets and Cost