<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Saidul Badhon</title>
    <description>The latest articles on DEV Community by Saidul Badhon (@saidulbadhon).</description>
    <link>https://dev.to/saidulbadhon</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4267268%2F829f16f0-c8ce-46c0-877d-10ef4ec3a8ad.jpg</url>
      <title>DEV Community: Saidul Badhon</title>
      <link>https://dev.to/saidulbadhon</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saidulbadhon"/>
    <language>en</language>
    <item>
      <title>AWS Security Alerts in an Afternoon: 5 Audit Commands and One CloudFormation Template</title>
      <dc:creator>Saidul Badhon</dc:creator>
      <pubDate>Thu, 26 Nov 2026 16:07:29 +0000</pubDate>
      <link>https://dev.to/saidulbadhon/aws-security-alerts-in-an-afternoon-5-audit-commands-and-one-cloudformation-template-464o</link>
      <guid>https://dev.to/saidulbadhon/aws-security-alerts-in-an-afternoon-5-audit-commands-and-one-cloudformation-template-464o</guid>
      <description>&lt;p&gt;On November 28, 2025, Sysdig &lt;a href="https://sysdig.com/blog/ai-assisted-cloud-intrusion-achieves-admin-access-in-8-minutes/" rel="noopener noreferrer"&gt;watched an attacker&lt;/a&gt; take test credentials from a public S3 bucket and have their own code running in the victim's Lambda function eight minutes later. Admin access followed in under ten.&lt;/p&gt;

&lt;p&gt;That is fast, but it is not unusual. Unit 42 &lt;a href="https://unit42.paloaltonetworks.com/malicious-operations-of-exposed-iam-keys-cryptojacking/" rel="noopener noreferrer"&gt;leaked keys to public GitHub on purpose&lt;/a&gt; and saw them used within five minutes. Clutch Security &lt;a href="https://www.clutch.security/blog/shattering-the-rotation-illusion-part-1-code-hosting-and-version-control-platforms" rel="noopener noreferrer"&gt;measured 6.6 minutes on average&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Most of us have no security team. This post is the setup I would do in an afternoon instead:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Five read-only commands that show where an account stands&lt;/li&gt;
&lt;li&gt;The AWS services worth switching on, with real prices&lt;/li&gt;
&lt;li&gt;One CloudFormation template that emails you on 20 high-risk CloudTrail events&lt;/li&gt;
&lt;li&gt;How to test the event patterns before you deploy anything&lt;/li&gt;
&lt;li&gt;The four traps that waste an afternoon&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Prices are for US East (N. Virginia), read on November 26, 2026.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fb1gn3yct96qt20n4z1xu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fb1gn3yct96qt20n4z1xu.png" alt="Chart: AWS quarantines a leaked key in 10 seconds, attackers first use it at 5 minutes, CloudTrail delivers the event in about 5 minutes, and attacker code was running at 8 minutes in one incident" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How the pieces fit
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API call  -&amp;gt;  CloudTrail  -&amp;gt;  EventBridge rule  -&amp;gt;  SNS topic  -&amp;gt;  email
              (about 5 min)   (pattern match)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CloudTrail &lt;a href="https://docs.aws.amazon.com/awscloudtrail/latest/userguide/how-cloudtrail-works.html" rel="noopener noreferrer"&gt;delivers within about 5 minutes of an API call on average&lt;/a&gt;, and AWS says that time is not guaranteed. So this pipeline tells you at roughly minute five. Keep that number in mind for the last section.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 0: audit what you have
&lt;/h2&gt;

&lt;p&gt;All five commands are read-only.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. Is root locked down? You want RootMFA 1 and RootAccessKeys 0.&lt;/span&gt;
aws iam get-account-summary \
  --query &lt;span class="s1"&gt;'SummaryMap.{RootMFA:AccountMFAEnabled,RootAccessKeys:AccountAccessKeysPresent}'&lt;/span&gt;

&lt;span class="c"&gt;# 2. Is there a trail, is it multi-Region, are the log files validated?&lt;/span&gt;
aws cloudtrail describe-trails \
  --query &lt;span class="s1"&gt;'trailList[].{Name:Name,MultiRegion:IsMultiRegionTrail,Validated:LogFileValidationEnabled}'&lt;/span&gt;

&lt;span class="c"&gt;# 3. Is GuardDuty on in every Region? 1 is on, 0 is off.&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; r &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;aws ec2 describe-regions --query &lt;span class="s1"&gt;'Regions[].RegionName'&lt;/span&gt; --output text&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$r $(aws guardduty list-detectors --region "&lt;/span&gt;&lt;span class="nv"&gt;$r&lt;/span&gt;&lt;span class="s2"&gt;" --query 'length(DetectorIds)' --output text)"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;

&lt;span class="c"&gt;# 4. Is there an Access Analyzer in this Region?&lt;/span&gt;
aws accessanalyzer list-analyzers --query &lt;span class="s1"&gt;'analyzers[].{Name:name,Type:type,Status:status}'&lt;/span&gt;

&lt;span class="c"&gt;# 5. Is public S3 access blocked for the whole account?&lt;/span&gt;
aws s3control get-public-access-block \
  --account-id &lt;span class="s2"&gt;"$(aws sts get-caller-identity --query Account --output text)"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CloudTrail's free 90-day event history already holds a lot. This is one account's console sign-ins, with the names changed. Two rows are the root user, and nothing on this page tells anyone.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhsy8u4h4v6t2bjo3hpxe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhsy8u4h4v6t2bjo3hpxe.png" alt="CloudTrail Event history filtered to ConsoleLogin, listing 21 sign-ins including two by the root user" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two results look like failures and are really findings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number 4 returning nothing means no analyzer exists in that Region.&lt;/li&gt;
&lt;li&gt;Number 5 returning &lt;code&gt;NoSuchPublicAccessBlockConfiguration&lt;/code&gt; means the account-level block was never set.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: turn on what AWS already gives you
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Switch&lt;/th&gt;
&lt;th&gt;What you get&lt;/th&gt;
&lt;th&gt;Cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;One multi-Region CloudTrail trail&lt;/td&gt;
&lt;td&gt;Management events kept in S3 past the free 90 days&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://aws.amazon.com/cloudtrail/pricing/" rel="noopener noreferrer"&gt;First copy free&lt;/a&gt;, plus S3 storage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GuardDuty in every Region&lt;/td&gt;
&lt;td&gt;Threat detection on CloudTrail, VPC flow and DNS logs, no rules to write&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://aws.amazon.com/guardduty/pricing/" rel="noopener noreferrer"&gt;Free for 30 days&lt;/a&gt;, then $4.00 per million CloudTrail management events and $1.00 per GB for the first 500 GB of flow and DNS logs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;IAM Access Analyzer&lt;/td&gt;
&lt;td&gt;A list of what is shared outside your account&lt;/td&gt;
&lt;td&gt;&lt;a href="https://aws.amazon.com/iam/access-analyzer/pricing/" rel="noopener noreferrer"&gt;External access findings are free&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cost Anomaly Detection&lt;/td&gt;
&lt;td&gt;A stolen key usually shows up on the bill first&lt;/td&gt;
&lt;td&gt;No additional charge&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;EventBridge rule to SNS&lt;/td&gt;
&lt;td&gt;The alerts below&lt;/td&gt;
&lt;td&gt;&lt;a href="https://aws.amazon.com/eventbridge/pricing/" rel="noopener noreferrer"&gt;AWS events on the default bus are free&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Create the trail in the console. The docs say all trails created there are multi-Region, and the console sets up the bucket policy for you.&lt;/p&gt;

&lt;p&gt;GuardDuty has to be enabled per Region. The Regions you never deploy to are the ones an attacker will use, so enable all of them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; r &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;aws ec2 describe-regions --query &lt;span class="s1"&gt;'Regions[].RegionName'&lt;/span&gt; --output text&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  aws guardduty create-detector --enable --region &lt;span class="s2"&gt;"$r"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That loop changes your account, and the 30-day trial starts per Region when you run it. Check the Usage page in the GuardDuty console before the trial ends.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: the alert template
&lt;/h2&gt;

&lt;p&gt;Save this as &lt;code&gt;aws-security-alerts.yaml&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;AWSTemplateFormatVersion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2010-09-09"&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Email a team address when a high-risk CloudTrail event happens in this Region.&lt;/span&gt;

&lt;span class="na"&gt;Parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;AlertEmail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;String&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Address that receives the alerts. Use a shared mailbox, not one person.&lt;/span&gt;

&lt;span class="na"&gt;Resources&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;AlertTopic&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::SNS::Topic&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;Subscription&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Protocol&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;email&lt;/span&gt;
          &lt;span class="na"&gt;Endpoint&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;AlertEmail&lt;/span&gt;

  &lt;span class="na"&gt;AlertTopicPolicy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::SNS::TopicPolicy&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;Topics&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;AlertTopic&lt;/span&gt;
      &lt;span class="na"&gt;PolicyDocument&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;Version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;
        &lt;span class="na"&gt;Statement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Effect&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Allow&lt;/span&gt;
            &lt;span class="na"&gt;Principal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
              &lt;span class="na"&gt;Service&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;events.amazonaws.com&lt;/span&gt;
            &lt;span class="na"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;sns:Publish&lt;/span&gt;
            &lt;span class="na"&gt;Resource&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;AlertTopic&lt;/span&gt;

  &lt;span class="na"&gt;HighRiskApiCalls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::Events::Rule&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Logging turned off, new credentials, public exposure, key deletion&lt;/span&gt;
      &lt;span class="na"&gt;EventPattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;detail-type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;AWS API Call via CloudTrail&lt;/span&gt;
        &lt;span class="na"&gt;detail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;eventName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;StopLogging&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;DeleteTrail&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;UpdateTrail&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;DeleteDetector&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;StopConfigurationRecorder&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;DeleteFlowLogs&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;CreateUser&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;CreateAccessKey&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;CreateLoginProfile&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;AttachUserPolicy&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;UpdateAssumeRolePolicy&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;AuthorizeSecurityGroupIngress&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;PutBucketPolicy&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;PutBucketAcl&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;DeleteBucketPublicAccessBlock&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;DeleteAccountPublicAccessBlock&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;ModifySnapshotAttribute&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;ScheduleKeyDeletion&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;DisableKey&lt;/span&gt;
      &lt;span class="na"&gt;Targets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Arn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;AlertTopic&lt;/span&gt;
          &lt;span class="na"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;email&lt;/span&gt;

  &lt;span class="na"&gt;RiskyConsoleSignIns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::Events::Rule&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Root sign-ins, and IAM users signing in without MFA&lt;/span&gt;
      &lt;span class="na"&gt;EventPattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;aws.signin&lt;/span&gt;
        &lt;span class="na"&gt;detail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;eventName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;ConsoleLogin&lt;/span&gt;
          &lt;span class="na"&gt;responseElements&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;ConsoleLogin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
              &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Success&lt;/span&gt;
          &lt;span class="na"&gt;$or&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;userIdentity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Root&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;userIdentity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;IAMUser&lt;/span&gt;
              &lt;span class="na"&gt;additionalEventData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="na"&gt;MFAUsed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"No"&lt;/span&gt;
      &lt;span class="na"&gt;Targets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Arn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;AlertTopic&lt;/span&gt;
          &lt;span class="na"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;email&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deploy it in us-east-1 first (see trap 1 below), then confirm the subscription email SNS sends you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws cloudformation deploy \
  --region us-east-1 \
  --stack-name security-alerts \
  --template-file aws-security-alerts.yaml \
  --parameter-overrides &lt;span class="nv"&gt;AlertEmail&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;security@example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What I verified, and what I did not.&lt;/strong&gt; The template passes &lt;code&gt;aws cloudformation validate-template&lt;/code&gt;, and both event patterns matched the right sample events in the test below. I have not deployed this exact stack to a live account, so I have not watched an email arrive from it. Deploy it to a sandbox account first.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why these events
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Group&lt;/th&gt;
&lt;th&gt;Events&lt;/th&gt;
&lt;th&gt;What it means&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Covering tracks&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;StopLogging&lt;/code&gt;, &lt;code&gt;DeleteTrail&lt;/code&gt;, &lt;code&gt;UpdateTrail&lt;/code&gt;, &lt;code&gt;DeleteDetector&lt;/code&gt;, &lt;code&gt;StopConfigurationRecorder&lt;/code&gt;, &lt;code&gt;DeleteFlowLogs&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Someone is switching off the things that record them&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Getting in, staying in&lt;/td&gt;
&lt;td&gt;Root &lt;code&gt;ConsoleLogin&lt;/code&gt;, &lt;code&gt;ConsoleLogin&lt;/code&gt; without MFA, &lt;code&gt;CreateUser&lt;/code&gt;, &lt;code&gt;CreateAccessKey&lt;/code&gt;, &lt;code&gt;CreateLoginProfile&lt;/code&gt;, &lt;code&gt;AttachUserPolicy&lt;/code&gt;, &lt;code&gt;UpdateAssumeRolePolicy&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;New credentials or wider permissions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Going public&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;AuthorizeSecurityGroupIngress&lt;/code&gt;, &lt;code&gt;PutBucketPolicy&lt;/code&gt;, &lt;code&gt;PutBucketAcl&lt;/code&gt;, &lt;code&gt;DeleteBucketPublicAccessBlock&lt;/code&gt;, &lt;code&gt;DeleteAccountPublicAccessBlock&lt;/code&gt;, &lt;code&gt;ModifySnapshotAttribute&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;A port, bucket or snapshot may now be open&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Destroying&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;ScheduleKeyDeletion&lt;/code&gt;, &lt;code&gt;DisableKey&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;A KMS key going away takes its data with it&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;AttachUserPolicy&lt;/code&gt; earns its place twice. It also fires when AWS quarantines a leaked key, because the quarantine is a policy attached to the user. The policy ARN is in the event's &lt;code&gt;requestParameters&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Some of these are noisy on a busy account. &lt;code&gt;AuthorizeSecurityGroupIngress&lt;/code&gt; fires for every rule, not just &lt;code&gt;0.0.0.0/0&lt;/code&gt;. Start with everything, then trim what your own pipeline does every day.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: test the patterns before you deploy
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;aws events test-event-pattern&lt;/code&gt; checks a pattern against a sample event without creating anything. This is how I tested the sign-in rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;PATTERN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{"source":["aws.signin"],"detail":{"eventName":["ConsoleLogin"],"responseElements":{"ConsoleLogin":["Success"]},"$or":[{"userIdentity":{"type":["Root"]}},{"userIdentity":{"type":["IAMUser"]},"additionalEventData":{"MFAUsed":["No"]}}]}}'&lt;/span&gt;

&lt;span class="nv"&gt;EVENT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{"version":"0","id":"1","detail-type":"AWS Console Sign In via CloudTrail","source":"aws.signin","account":"111122223333","time":"2026-11-26T00:00:00Z","region":"us-east-1","resources":[],"detail":{"eventName":"ConsoleLogin","userIdentity":{"type":"IAMUser"},"responseElements":{"ConsoleLogin":"Success"},"additionalEventData":{"MFAUsed":"No"}}}'&lt;/span&gt;

aws events test-event-pattern --event-pattern &lt;span class="s2"&gt;"$PATTERN"&lt;/span&gt; --event &lt;span class="s2"&gt;"$EVENT"&lt;/span&gt;
&lt;span class="c"&gt;# { "Result": true }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I ran nine cases across the two rules. Root sign-in, IAM user without MFA, &lt;code&gt;StopLogging&lt;/code&gt; and &lt;code&gt;CreateAccessKey&lt;/code&gt; matched. An IAM user with MFA, a failed login, a single sign-on session and &lt;code&gt;DescribeInstances&lt;/code&gt; did not.&lt;/p&gt;

&lt;h2&gt;
  
  
  The four traps
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. IAM lives in us-east-1.&lt;/strong&gt; IAM, STS and CloudFront are global services, and CloudTrail &lt;a href="https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-concepts.html" rel="noopener noreferrer"&gt;records their events in US East (N. Virginia)&lt;/a&gt;. A rule in eu-west-1 will never see &lt;code&gt;CreateAccessKey&lt;/code&gt;. Root sign-ins &lt;a href="https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-aws-console-sign-in-events.html" rel="noopener noreferrer"&gt;land in us-east-1, us-east-2 or us-west-2&lt;/a&gt;. Deploy the stack in us-east-1, then in those two, then in every Region you run workloads in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. &lt;code&gt;MFAUsed&lt;/code&gt; is always &lt;code&gt;No&lt;/code&gt; for single sign-on.&lt;/strong&gt; AWS only sets it for IAM users and root. Without the &lt;code&gt;IAMUser&lt;/code&gt; filter, every SSO login emails you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. S3 event names differ from the API.&lt;/strong&gt; The API call &lt;code&gt;DeletePublicAccessBlock&lt;/code&gt; appears in CloudTrail as &lt;code&gt;DeleteBucketPublicAccessBlock&lt;/code&gt; or &lt;code&gt;DeleteAccountPublicAccessBlock&lt;/code&gt;. Match the CloudTrail name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Read-only calls need a different rule state.&lt;/strong&gt; A rule in the default &lt;code&gt;ENABLED&lt;/code&gt; state &lt;a href="https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event-cloudtrail.html" rel="noopener noreferrer"&gt;does not match read-only management events&lt;/a&gt;. To alert on something like &lt;code&gt;GetSecretValue&lt;/code&gt;, set the rule's state to &lt;code&gt;ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS&lt;/code&gt;. You also need a trail that is logging, or none of these rules receive anything.&lt;/p&gt;

&lt;p&gt;One more: the docs spell the sign-in &lt;code&gt;detail-type&lt;/code&gt; two ways (&lt;code&gt;AWS Console Sign In via CloudTrail&lt;/code&gt; and &lt;code&gt;AWS Console Signin via CloudTrail&lt;/code&gt;). The pattern above matches on &lt;code&gt;source: aws.signin&lt;/code&gt; so it does not depend on either.&lt;/p&gt;

&lt;h2&gt;
  
  
  If you would rather not maintain rules
&lt;/h2&gt;

&lt;p&gt;AWS shipped two things that cover some of this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://aws.amazon.com/about-aws/whats-new/2026/09/guardduty-optional-detection-rules/" rel="noopener noreferrer"&gt;GuardDuty Custom Detection Rules&lt;/a&gt; (September 2026): it launched with 35 prebuilt, opt-in rules on CloudTrail management events, and the console listed 90 when I looked on November 26, 2026. Every rule starts disabled and has a 14-day dry-run mode.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/security-ir/latest/userguide/what-is.html" rel="noopener noreferrer"&gt;AWS Security Incident Response&lt;/a&gt;: triages your GuardDuty findings and contacts you when one is real. &lt;a href="https://aws.amazon.com/security-incident-response/pricing/" rel="noopener noreferrer"&gt;The first 10,000 findings a month are free&lt;/a&gt;. It triages findings from other services and does not generate its own.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqnuycpgjxqpypz99q3s0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqnuycpgjxqpypz99q3s0.png" alt="The GuardDuty Custom Detection Rules page listing 90 AWS-managed rules, all disabled by default" width="799" height="538"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What this does not solve
&lt;/h2&gt;

&lt;p&gt;You now get an email at about minute five. It is a block of JSON. It does not say whether that &lt;code&gt;CreateAccessKey&lt;/code&gt; was your deploy pipeline or a stranger, and at 3 a.m. nobody reads it until morning.&lt;/p&gt;

&lt;p&gt;That gap is the real work. Someone has to look at who did it, from where, and what else they did in the same few minutes. Staffing that around the clock takes 4.2 people per seat (168 hours in a week, 40 in a working one), which is about $542,556 a year at the &lt;a href="https://www.bls.gov/ooh/computer-and-information-technology/information-security-analysts.htm" rel="noopener noreferrer"&gt;US median analyst wage&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Disclosure: I work on &lt;a href="https://jutsu.ai" rel="noopener noreferrer"&gt;Jutsu&lt;/a&gt;, which does that first investigation in software and asks before it acts. The longer version of this post, with the cost comparison and screenshots, is &lt;a href="https://jutsu.ai/blog/how-to-monitor-aws-security-without-a-soc-team" rel="noopener noreferrer"&gt;on the Jutsu blog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Whatever you choose, decide who answers the alert. A rule nobody reads is a log.&lt;/p&gt;

&lt;p&gt;What would you add to the event list? I left out &lt;code&gt;RunInstances&lt;/code&gt; and &lt;code&gt;PutRolePolicy&lt;/code&gt; to keep the noise down, and I am not sure that was right.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>security</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
