AWS Builder Center

Your S3 Bucket Is Public. Can AWS Detect It Before an Attacker Does?

Building an automated cloud security guardrail using AWS Config, Amazon EventBridge, and AWS Lambda.

Imagine deploying a simple web application on AWS.
Your application works perfectly. Your infrastructure is scalable. Your data is stored securely in Amazon S3.
Then, one day, a developer changes a bucket policy.
A bucket that was supposed to be private becomes publicly accessible.
No malware was installed. No vulnerability was exploited. No sophisticated attack was required.
Just one configuration change.
This is one of the most dangerous realities of cloud security: sometimes, the biggest security incident starts with a small configuration mistake.
Cloud environments change continuously. Developers deploy resources, modify permissions, and update infrastructure. Manually reviewing every change is not a scalable security strategy.
So, what if we could automatically detect risky configurations and trigger a security response?
In this article, we'll build a simple cloud security monitoring architecture using AWS Config, Amazon EventBridge, and AWS Lambda.

The Real-World Problem

Amazon S3 is widely used to store application files, backups, logs, and business data.
However, an incorrectly configured bucket can expose sensitive information.
Some common causes include:
  • Misconfigured bucket policies.
  • Incorrect access control settings.
  • Accidental public access.
  • Security controls being disabled during development.
  • Changes that go unnoticed after deployment.
The challenge is not just preventing misconfiguration.
It is continuously detecting when the security posture of a resource changes.

Our Solution: Automated S3 Security Monitoring

Instead of relying on manual reviews, we can use AWS Config to evaluate resource configurations and EventBridge to trigger an automated response.

Architecture

Amazon S3
Bucket Configuration
|
v
AWS Config
Configuration Evaluation
|
v
Amazon EventBridge
Security Rule
|
v
AWS Lambda
Response Handler
|
+----+-----+
| |
v v
Amazon SNS Audit Logs
Notification (CloudWatch)
The architecture follows a simple principle:
Detect → Evaluate → Alert → Respond

What Each AWS Service Does

Amazon S3
Stores the data that needs to be protected.
AWS Config
Continuously records and evaluates AWS resource configurations. It can use managed rules to check whether S3 buckets meet security requirements.
Amazon EventBridge
Receives configuration compliance events and routes matching events to Lambda.
AWS Lambda
Processes the event and executes predefined response logic.
Amazon SNS
Notifies the security team when a potentially risky configuration is detected.
Amazon CloudWatch
Provides logs and monitoring for the Lambda function.

Step 1: Enable AWS Config

AWS Config helps track configuration changes and evaluate resources against desired security requirements.
For this project:
  1. Open the AWS Config console.
  1. Enable AWS Config in your test account and Region.
  1. Configure a suitable recording scope for S3 resources.
  1. Create a managed rule to evaluate S3 public-access configuration.
For example, AWS Config provides managed rules such as:
  •  s3-bucket-public-read-prohibited 
  •  s3-bucket-public-write-prohibited 
These rules help identify buckets that violate the corresponding public-access requirements.
The rules should be selected based on the security requirements of the environment.

Step 2: Create an EventBridge Rule

AWS Config publishes compliance-related events that can be evaluated by EventBridge.
We can create a rule that reacts when a resource becomes noncompliant.
Example event pattern:
{
"source": [
"aws.config"
],
"detail-type": [
"Config Rules Compliance Change"
],
"detail": {
"messageType": [
"ComplianceChangeNotification"
],
"newEvaluationResult": {
"complianceType": [
"NON_COMPLIANT"
]
}
}
}
This example filters for noncompliance events.
For a production system, the rule should also be scoped to the relevant AWS Config rule names and resource types to avoid unnecessary notifications.

Step 3: Create an SNS Security Alert

Create an SNS topic named:
 S3SecurityAlerts 
Subscribe a security administrator's email address to the topic.
After confirming the subscription, the topic can deliver notifications when an S3 resource violates a security rule.

Step 4: Build the Lambda Response Handler

The following Python code demonstrates a basic alerting handler.
import json
import os
import boto3

sns = boto3.client("sns")

TOPIC_ARN = os.environ["SNS_TOPIC_ARN"]

def lambda_handler(event, context):

detail = event.get("detail", {})

resource_id = detail.get(
"resourceId",
"Unknown"
)

compliance = detail.get(
"newEvaluationResult", {}
).get(
"complianceType",
"Unknown"
)

rule_name = detail.get(
"configRuleName",
"Unknown"
)

message = {
"resource": resource_id,
"compliance": compliance,
"config_rule": rule_name,
"region": event.get("region")
}

sns.publish(
TopicArn=TOPIC_ARN,
Subject="S3 Security Configuration Alert",
Message=json.dumps(message, indent=2)
)

return {
"statusCode": 200,
"body": "Security alert generated"
}
Configure the  SNS_TOPIC_ARN  environment variable with the SNS topic ARN.
The Lambda execution role must have permission to publish to the designated SNS topic.
EventBridge also needs permission to invoke the Lambda function.
This implementation is an alerting demonstration. Before using it in production, validate the event schema, handle duplicate events, and ensure that the IAM permissions are restricted to the required resources.

Step 5: Test the Security Monitoring Workflow

Use a dedicated test bucket in a non-production AWS account.
Perform the following experiment:
  1. Create a test S3 bucket.
  1. Configure AWS Config to evaluate the bucket.
  1. Introduce a controlled configuration change that violates the selected rule.
  1. Verify the compliance evaluation.
  1. Confirm that EventBridge receives the corresponding event.
  1. Check the Lambda execution logs.
  1. Verify that the SNS notification reaches the subscribed email address.
AWS Config evaluation and event delivery are asynchronous, so the alert may not appear immediately.
Do not expose real customer data or production resources during testing.

Should We Automatically Fix the Misconfiguration?

This is where cloud security becomes interesting.
Detection is useful, but remediation can be even more powerful.
For example, a response system could:
  • Notify the security administrator.
  • Open an incident ticket.
  • Trigger a remediation workflow.
  • Restrict access after validating the resource state.
  • Request human approval before making a sensitive change.
However, automatic remediation must be carefully designed.
A bucket may be intentionally public because it hosts static website content. Automatically blocking access could disrupt a legitimate service.
A better architecture considers context before taking action.
A secure cloud system should not blindly fix every violation. It should understand the intended security policy and the impact of the response.

Security Best Practices

1. Use Least-Privilege IAM

Lambda should only receive the permissions required for its specific task.
Avoid attaching broad administrator permissions.

2. Separate Detection from Remediation

Use one component to detect violations and another to perform approved corrective actions.
This improves auditability and reduces accidental impact.

3. Protect the Monitoring System

An attacker who can disable AWS Config or modify EventBridge rules may be able to bypass monitoring.
Restrict administrative access to security controls.

4. Maintain an Audit Trail

Record configuration changes, compliance results, alert delivery, and remediation outcomes.

5. Test Your Security Controls

A security rule that has never been tested may not work as expected during an incident.
Regularly validate detection and response behavior in a controlled environment.

What We Learned

This project demonstrates how multiple AWS services can work together to build an event-driven security monitoring system.
The important lesson is that cloud security is not a one-time configuration task.
Resources change. Permissions evolve. Applications grow.
Security must evolve with them.
By combining AWS Config, EventBridge, Lambda, and SNS, we can create a foundation for continuous cloud security monitoring.
This architecture can later be extended with AWS Security Hub, AWS Systems Manager Automation, ticketing integrations, and multi-account monitoring.

Conclusion

Cloud security incidents do not always begin with sophisticated attacks.
Sometimes, they begin with a simple configuration mistake.
The goal of cloud security automation is to reduce the time between a risky change and an appropriate response.
With AWS Config, Amazon EventBridge, and AWS Lambda, we can move from manual security reviews toward continuous, event-driven monitoring.
The next step is to extend this architecture to additional resources, such as IAM policies, EC2 security groups, and other critical cloud configurations.
Build cloud infrastructure that doesn't just work — build cloud infrastructure that continuously checks whether it is still secure.


This article is intended for educational purposes. Test all configurations in a non-production AWS environment before applying them to production workloads.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article