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

A production security group rule disappeared overnight. How do you find out who removed it?

BeginnerTroubleshootingCloudFormation, CloudWatch, KMS, Secrets and Cost
Answer

Likely causes → A manual console change, an automation job, or an IaC apply that removed the rule as drift.

Diagnose →

aws cloudtrail lookup-events --lookup-attributes AttributeKey=ResourceName,AttributeValue=sg-0abc \
  --start-time $(date -u -d '-2 day' +%FT%TZ) \
  --query 'Events[].[EventTime,EventName,Username]' --output table
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=RevokeSecurityGroupIngress --max-results 10
aws configservice get-resource-config-history --resource-type AWS::EC2::SecurityGroup --resource-id sg-0abc --limit 5

Fix →

  1. Restore the rule through IaC
  2. Find the principal (userIdentity.arn, sourceIPAddress, user agent such as Terraform) and close the gap

Prevent → Keep an organization trail with Athena queries, AWS Config rules for SG baselines, and EventBridge alerts on SG changes in production. Note that lookup-events covers only 90 days of management events.

aws All AWS questions Roadmap: Cloud cost & architecture

More on CloudFormation, CloudWatch, KMS, Secrets and Cost