Skip to content

fix(s3): emit API reasons and bucket resources in EventBridge events - #9141

Open
aniketshukla1 wants to merge 2 commits into
floci-io:mainfrom
aniketshukla1:fix/s3-eventbridge-created-reason-9135
Open

aniketshukla1 wants to merge 2 commits into
floci-io:mainfrom
aniketshukla1:fix/s3-eventbridge-created-reason-9135

Conversation

@aniketshukla1

@aniketshukla1 aniketshukla1 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

S3 Object Created events sent through EventBridge currently carry classic notification names such as ObjectCreated:Put and an empty resources list. Consumers filtering for PutObject or the bucket ARN therefore miss them.

Map the four creation paths to PutObject, POST Object, CopyObject, and CompleteMultipartUpload. Build the event entry through the shared EventBridge helper with the bucket's partition-aware ARN.

Closes #9135.

Type of change

  • Bug fix (fix:)
  • New feature (feat:)
  • Breaking change (feat!: or fix!:)
  • Docs / chore

AWS Compatibility

Matches the documented S3 EventBridge event structure for creation reasons and bucket resources.

New integration coverage uses AWS SDK for Java 2.57.7 for S3 operations, EventBridge rules, SQS delivery, and event-pattern matching. Browser POST uses multipart HTTP. Five cases cover all four creation APIs and a China-region bucket. Before the fix, every case failed on its reason, missing bucket ARN, and the consumer's reason/resource filter. Existing classic notification and lifecycle tests also pass.

690 tests passed, none skipped, plus zero Checkstyle violations and passing docs/partition gates:

JAVA_HOME=/opt/homebrew/opt/openjdk@25/libexec/openjdk.jdk/Contents/Home \
MAVEN_OPTS=-Xmx4g ./mvnw -o test checkstyle:check \
  '-Dtest=S3ServiceTest,S3IntegrationTest,S3EventBridge*Test,S3PresignedPostIntegrationTest,S3NotificationModelTest,S3Lifecycle*Test,EventBridgeServiceTest,EventBridgeInputTransformerIntegrationTest' \
  -Dfloci.services.lambda.reconcile-containers-on-startup=false \
  -Dfloci.services.ec2.reconcile-containers-on-startup=false \
  -Dfloci.services.ecs.reconcile-containers-on-startup=false \
  -Dfloci.services.emr.reconcile-containers-on-startup=false \
  -Dfloci.services.emrserverless.reconcile-containers-on-startup=false
make docs-check partition-check

The fixture registers SDK clients and resources with the existing PartitionCleanup helper immediately after creation. Four fault-injection cases reproduce setup leaks and cleanup masking the original error. On the current fixture revision, 28 tests passed, none skipped, using -Dtest=S3EventBridge*Test,PartitionCleanupTest with the startup flags above. Checkstyle, docs, and partition gates also passed. The 690-test result above was run before this fixture-only cleanup change.

Full repository tests, native builds, Docker compatibility suites, live AWS, and AWS CLI checks were not run locally.

Checklist

  • ./mvnw test passes locally (focused suite above passed; full suite not run)
  • New or updated integration test added
  • Commit messages follow Conventional Commits
  • I have no more than 2 open, non-draft pull requests and no more than 4 open pull requests in total (drafts included) in this repository (maintainers and dependency bots are exempt).

@qodo-code-review

qodo-code-review Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Fix S3 EventBridge creation reasons and bucket resources

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Map S3 object-creation events to API-specific EventBridge reasons so consumers can filter by
 operation.
• Include partition-aware bucket ARNs in EventBridge resources so bucket filters match.
• Add integration coverage for four creation APIs and a China-region bucket.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed producer, EventBridge envelope, rule matching, and downstream targets implement one bounded integration outcome: routing an S3 object event to configured EventBridge rules.
  • The bucket ARN is an envelope attribute consumed by resource-filtered rules, not an independent capability.
  • The reason mapping is another contract attribute of the same S3-to-EventBridge routing capability.
  • It changes which configured EventBridge rules and targets recognize the event, not a separate functional scope.
Sources

src/main/java/io/floci/aws/services/eventbridge/EventBridgeService.java[1060-1075]

     * The entry an AWS service sends on its own behalf, for {@link #putEvents}. {@code Resources} is
     * always present, because rule matching reads it for any rule with a {@code resources} filter,
     * and holds {@code resourceArn} unless that is null or blank. With no {@code EventBusName} the
     * entry goes to the default bus; the map is mutable so a caller can name another.
     */
    public static Map<String, Object> serviceEventEntry(String source, String detailType, String detail,
                                                        String resourceArn) {
        ArrayNode resources = JsonNodeFactory.instance.arrayNode();
        if (resourceArn != null && !resourceArn.isBlank()) {
            resources.add(resourceArn);
        }
        Map<String, Object> entry = new HashMap<>();
        entry.put("Source", source);
        entry.put("DetailType", detailType);
        entry.put("Detail", detail);
        entry.put("Resources", resources);
Behavioral complexity 🟡 Medium 🧩 Compatibility cases

  • Before: EventBridge detail.reason used the classic S3 notification event name, with only lifecycle deletion translated.
  • After: creation events are translated into API-specific names while lifecycle and other events retain fallback behavior.
  • New correctness condition: every supported creation entry point must map to the exact API reason expected by existing EventBridge consumers, while deletion, annotation, and lifecycle semantics remain unchanged.
  • The switch itself is simple; the compatibility condition is introduced by changing the external event contract across multiple operation variants.
Potential damage 🟡 Medium 🩹 Temporary loss

  • A wrong bucket ARN can suppress delivery to resource-filtered EventBridge rules and their targets for affected S3 events.
  • The S3 write is not lost and the issue is recoverable by correcting the code/configuration and replaying or reissuing missed events, but reverting code does not retroactively deliver events already filtered out.
  • Code rollback prevents future malformed events but does not repair already missed EventBridge deliveries.
  • Recovery requires a new triggering operation or an available/manual replay mechanism; no automatic replay path was established.
Assessed commit c701c23
Diagram

sequenceDiagram
    actor Client
    participant S3 as S3 Service
    participant ARNs as S3 Resource ARNs
    participant EB as EventBridge Service
    participant SQS as SQS Queue
    actor Consumer
    Client->>S3: Create object
    S3->>ARNs: Get partition-aware bucket ARN
    ARNs-->>S3: Bucket ARN
    S3->>EB: Publish API reason and bucket resource
    EB->>SQS: Deliver matching event
    SQS-->>Consumer: Return event
Loading
High-Level Assessment

Keep the mapping in the EventBridge-specific path so classic notification names remain unchanged. Reusing the existing event-entry helper and bucket ARN formatter avoids duplicating event-envelope and partition logic; no materially better architectural alternative is apparent.

Files changed (2) +129 / -6

Bug fix (1) +11 / -6
S3Service.javaEmit API creation reasons and bucket resources +11/-6

Emit API creation reasons and bucket resources

• Maps the four object-creation notification names to EventBridge API reasons while retaining the existing fallback for other events. Builds EventBridge entries with the shared helper and a partition-aware bucket ARN in Resources.

src/main/java/io/floci/aws/services/s3/S3Service.java

Tests (1) +118 / -0
S3EventBridgeEventShapeIntegrationTest.javaVerify S3 creation event shape and rule matching +118/-0

Verify S3 creation event shape and rule matching

• Adds five integration cases covering PUT, browser POST, copy, multipart completion, and a China-region PUT. Checks delivery through EventBridge to SQS, event fields, bucket ARN resources, and reason/resource event-pattern matching.

src/test/java/io/floci/aws/services/s3/S3EventBridgeEventShapeIntegrationTest.java

@qodo-code-review

qodo-code-review Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Test bucket leaks when queue or rule setup fails ✓ Resolved

Resolving commit: c701c23

Resolution reason
Cleanup is now registered right after each successful creation via a PartitionCleanup extension
(@RegisterExtension), so resources are removed even when a later setup step throws. A new test class
verifies cleanup continues past failing steps.
Description
The test creates the bucket at line 50 and the queue at line 56 before the cleanup try block
begins at line 60, so a throw from sqs.getQueueAttributes or events.putRule leaves the bucket
and queue orphaned in the shared emulator. Cleanup is only registered once the inner try is
entered, which breaks the rule that cleanup be registered immediately after each successful
creation. Inside finally, the deletes are also unguarded, so a failing deleteObject or
removeTargets skips the later deleteBucket and leaks the bucket even on the success path.

Grey Divider

Context sources
⚠️ Tickets: not configured — No jira, linear integration is connected for the linked tickets
✅ Compliance rules (platform): 21 rules
✅ Cross-repo context — repo relationships
Review mode: Auto: ⚖️ Balanced: Localized runtime contract fix with focused coverage; standard review fits.

Grey Divider

Tip of the day
💡 Did you know, you can add REVIEW.md to your repo root and Qodo follows it on every PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@pgermosen pgermosen added bug Something isn't working s3 Amazon Simple Storage Service (S3) labels Nov 21, 2026

@pgermosen pgermosen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aniketshukla1 thanks, the creation reasons and the bucket ARN match the S3 EventBridge event docs.

Two things. The rewritten eventBridgeReason still falls back to the classic name for the other events. The same page sets DeleteObject for an API deletion and shows PutObjectAnnotation and DeleteObjectAnnotation for annotations. Could you map ObjectRemoved:* and ObjectAnnotation:Put/Delete in the same switch?

In the test, the queue and rule wiring is what EventRuleQueue in io.floci.aws.testing already does. Using it in a try-with-resources also removes the leak if setup fails.

@pgermosen pgermosen added the waiting-author Review posted; waiting on the PR author to respond label Nov 21, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working s3 Amazon Simple Storage Service (S3) waiting-author Review posted; waiting on the PR author to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] S3 EventBridge events: detail.reason is "ObjectCreated:Put" instead of "PutObject", and resources is empty

2 participants