BrainyBeeBrainyBee
ExploreBlogStart Studying
HomeAWS Certified DevOps Engineer - Professional (DOP-C02)Lab: Automating Event-Driven Security Notifications with Amazon EventBridge
Hands-On Lab1,050 words

Lab: Automating Event-Driven Security Notifications with Amazon EventBridge

Manage event sources to process, notify, and take action in response to events

Lab: Automating Event-Driven Security Notifications with Amazon EventBridge

In this lab, you will build a serverless event-processing workflow that detects when a new Amazon S3 bucket is created and sends an automated notification via Amazon SNS. This follows the AWS DevOps Engineer Professional domain for managing event sources to process, notify, and take action.


Prerequisites

  • An active AWS Account.
  • AWS CLI installed and configured with Administrator credentials.
  • Basic knowledge of JSON for event patterns.
  • Region: Ensure you are working in us-east-1 for consistency.

[!WARNING] This lab involves creating resources that may incur costs if not deleted. Ensure you complete the Teardown section.

Learning Objectives

  • Configure an Amazon SNS Topic for event fan-out.
  • Create an AWS Lambda function to process event metadata.
  • Implement an Amazon EventBridge Rule to capture AWS API calls from CloudTrail.
  • Grant cross-service permissions for event routing.

Architecture Overview

Loading Diagram...
Figure 1 — Mermaid diagram

Step-by-Step Instructions

Step 1: Create an Amazon SNS Topic

We need a destination to "fan out" our notifications.

bash
# Create the SNS topic aws sns create-topic --name brainybee-event-alerts # Subscribe your email (Replace placeholder) aws sns subscribe --topic-arn arn:aws:sns:us-east-1:<YOUR_ACCOUNT_ID>:brainybee-event-alerts --protocol email --notification-endpoint <YOUR_EMAIL_ADDRESS>

[!IMPORTANT] You must check your email inbox and click Confirm Subscription before you can receive messages.

▶Console alternative

Navigate to

SNS > Topics > Create topic

. Select

Standard

, name it

brainybee-event-alerts

. Once created, click

Create subscription

, select

Email

, and enter your address.

Step 2: Create the Lambda Execution Role

Lambda needs permission to write logs to CloudWatch and publish to SNS.

  1. Create a file named trust-policy.json:
    json
    { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": { "Service": "lambda.amazonaws.com" }, "Action": "sts:AssumeRole" }] }
  2. Create the role:
    bash
    aws iam create-role --role-name brainybee-lambda-event-role --assume-role-policy-document file://trust-policy.json # Attach basic execution and SNS publish policies aws iam attach-role-policy --role-name brainybee-lambda-event-role --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole aws iam attach-role-policy --role-name brainybee-lambda-event-role --policy-arn arn:aws:iam::aws:policy/AmazonSNSFullAccess

Step 3: Create the Lambda Processing Function

This function will parse the S3 event and send a formatted alert.

  1. Create index.mjs:
    javascript
    import { SNSClient, PublishCommand } from "@aws-sdk/client-sns"; const sns = new SNSClient({}); export const handler = async (event) => { console.log("Event Received:", JSON.stringify(event, null, 2)); const bucketName = event.detail.requestParameters.bucketName; const region = event.detail.awsRegion; const message = `Security Alert: A new S3 bucket was created.\nBucket Name: ${bucketName}\nRegion: ${region}`; await sns.send(new PublishCommand({ TopicArn: process.env.SNS_TOPIC_ARN, Message: message, Subject: "S3 Security Notification" })); };
  2. Zip and deploy:
    bash
    zip function.zip index.mjs aws lambda create-function --function-name brainybee-s3-notifier \ --runtime nodejs18.x --role arn:aws:iam::<YOUR_ACCOUNT_ID>:role/brainybee-lambda-event-role \ --handler index.handler --zip-file fileb://function.zip \ --environment Variables={SNS_TOPIC_ARN=arn:aws:sns:us-east-1:<YOUR_ACCOUNT_ID>:brainybee-event-alerts}

Step 4: Configure the EventBridge Rule

We will create a rule that triggers whenever CloudTrail records a CreateBucket event.

bash
# Create the rule aws events put-rule --name "S3CreateBucketRule" --event-pattern '{ "source": ["aws.s3"], "detail-type": ["AWS API Call via CloudTrail"], "detail": { "eventSource": ["s3.amazonaws.com"], "eventName": ["CreateBucket"] } }' # Add Lambda as the target aws events put-targets --rule "S3CreateBucketRule" --targets "Id"="1","Arn"="arn:aws:lambda:us-east-1:<YOUR_ACCOUNT_ID>:function:brainybee-s3-notifier" # Grant EventBridge permission to invoke Lambda aws lambda add-permission --function-name brainybee-s3-notifier --statement-id EventBridgeInvoke --action lambda:InvokeFunction --principal events.amazonaws.com --source-arn arn:aws:events:us-east-1:<YOUR_ACCOUNT_ID>:rule/S3CreateBucketRule

Checkpoints

  1. Trigger the Event: Create a dummy S3 bucket.
    bash
    aws s3 mb s3://brainybee-test-event-$(date +%s)
  2. Verify Logs: Check CloudWatch Logs to see if the Lambda executed.
    bash
    aws logs describe-log-streams --log-group-name /aws/lambda/brainybee-s3-notifier
  3. Check Email: Verify you received the "S3 Security Notification" message.

Clean-Up / Teardown

[!WARNING] Failure to delete these resources will result in ongoing (though minimal) CloudWatch Log storage costs.

bash
# Delete S3 test bucket aws s3 rb s3://<YOUR_TEST_BUCKET_NAME> # Delete EventBridge Rule and Target aws events remove-targets --rule "S3CreateBucketRule" --ids "1" aws events delete-rule --name "S3CreateBucketRule" # Delete Lambda and IAM Role aws lambda delete-function --function-name brainybee-s3-notifier aws iam detach-role-policy --role-name brainybee-lambda-event-role --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole aws iam detach-role-policy --role-name brainybee-lambda-event-role --policy-arn arn:aws:iam::aws:policy/AmazonSNSFullAccess aws iam delete-role --role-name brainybee-lambda-event-role # Delete SNS Topic aws sns delete-topic --topic-arn arn:aws:sns:us-east-1:<YOUR_ACCOUNT_ID>:brainybee-event-alerts

Troubleshooting

ErrorCauseFix
No notification receivedSubscription not confirmedCheck email spam folder and confirm subscription.
Lambda not triggeredEvent pattern mismatchCheck if CloudTrail is enabled in the region. EventBridge relies on CloudTrail for S3 API events.
AccessDenied in LambdaMissing SNS permissionEnsure the IAM role has AmazonSNSFullAccess or a custom policy for the topic.

Stretch Challenge

Automated Remediation: Modify the Lambda function to check if the new bucket has a specific tag (e.g., Compliance=Internal). If the tag is missing, have the Lambda function automatically apply it or delete the bucket.

Cost Estimate

ServiceUsageCost
AWS LambdaFirst 1M requests/mo free$0.00
EventBridgeManagement events are free$0.00
SNSFirst 1,000 emails/mo free$0.00
S3Storage < 5GB (Free Tier)$0.00
Total$0.00

Concept Review

In this lab, we utilized an Event-Driven Architecture. This design pattern is asynchronous and decoupled, meaning the S3 service doesn't need to know about the notification logic.

Compiling TikZ diagram…
⏳
Running TeX engine…
This may take a few seconds
Figure 2 — TikZ diagram

Comparison: EventBridge vs. S3 Event Notifications

FeatureS3 Event NotificationsAmazon EventBridge
DestinationsSNS, SQS, Lambda20+ AWS Services, SaaS
Cross-AccountDifficultNative Support
Advanced FilteringLimited (Prefix/Suffix)Deep JSON Pattern Matching
Schema RegistryNoYes
All AWS Certified DevOps Engineer - Professional (DOP-C02) Study Resources

Related Notes

  • Mastering Event-Driven Response: Processing, Notification, and Action875 words
  • Mastering AWS Alerting and Automated Remediation1,050 words
  • Study Guide: Analyzing Failed Deployments in AWS940 words
  • Incident Analysis: Troubleshooting Failed Processes in AWS1,050 words
  • Mastering AWS Monitoring & Security Analytics: Logs, Metrics, and Findings1,050 words
  • AWS Log Analysis: Athena, CloudWatch Insights, and OpenSearch920 words
  • Analyzing Real-Time Log Streams with Amazon Kinesis Data Streams985 words
  • CloudWatch Anomaly Detection Alarms: Professional Study Guide820 words
  • AWS Application Storage Patterns: EBS, EFS, and S31,054 words
  • Lab: Automating Security Controls and Data Protection with AWS Secrets Manager and Config942 words
  • Master Study Guide: Automating Security Controls & Data Protection (AWS DOP-C02)1,184 words
  • Mastering AWS CloudFormation StackSets: Multi-Account & Multi-Region Orchestration895 words

Ready to study AWS Certified DevOps Engineer - Professional (DOP-C02)?

Practice tests, flashcards, and all study notes — free, no sign-up.

Start Studying

Ready to study AWS Certified DevOps Engineer - Professional (DOP-C02)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free
AWS Certified DevOps Engineer - Professional (DOP-C02) ResourcesExplore All HivesBlogHome

© 2026 BrainyBee. Free AI-powered exam prep.

Loading Diagram...
Flowchart, left to right. S3 Service connects to AWS CloudTrail ("CreateBucket API"). B connects to Amazon EventBridge ("Management Event"). C connects to AWS Lambda ("Trigger"). D connects to Amazon SNS Topic ("Publish"). E connects to Subscriber (Email) ("Notify").