Security & FinOps · Freelance

Automated IAM Compromise Detection and Credential Revocation

A SAM stack watches CloudTrail logs for access-denied bursts and automatically strips credentials from the offending IAM user.

  • CloudTrail
  • CloudWatch Logs
  • Contributor Insights
  • Lambda
  • IAM
  • SNS
  • S3
  • SAM

// Overview

The template creates a trail delivering to S3 and CloudWatch Logs. A Lambda subscribed to AccessDenied and UnauthorizedOperation error codes decodes the log batch, extracts the principal, notifies an email-subscribed SNS topic, deletes the access key and removes the console login profile. A Contributor Insights rule groups activity by principal and event.

// The problem

Compromised credentials generate bursts of unauthorised calls; immediate automatic containment plus notification was needed.

// Flow

Automated IAM Compromise Detection and Credential Revocation flow1. CloudTrail → 2. Log filter → 3. Lambda trigger → 4. Decode → 5. Notify → 6. Revoke keys → 7. Revoke console → 8. Observability01CloudTrail02Log filter03Lambda trigger04Decode05Notify06 · GATERevoke keys07Revoke console08Observability
  1. CloudTrailtrail logging to S3 and CloudWatch Logs
  2. Log filterpattern on AccessDenied and UnauthorizedOperation
  3. Lambda triggersubscription event on the function
  4. Decodebase64 and gzip decode, parse the identity
  5. NotifySNS email naming the suspected principal
  6. Revoke keys gatedelete the access key used in the event
  7. Revoke consoledelete the login profile
  8. Observabilitylog retention and Contributor Insights rule

// Design decisions & guardrails

  • Fully event-driven and serverless.
  • Containment first, humans notified immediately after.
  • A production version should scope the function role and the trigger threshold; both are called out as follow-ups.

// Outcome

Seconds from anomalous activity to revoked credentials and an alert.

// Related