Skip to content

fix(data-classes): don't URL-decode the object key of S3 EventBridge events - #8900

Open
nc-dirknilius wants to merge 1 commit into
aws-powertools:developfrom
nc-dirknilius:fix/s3-eventbridge-object-key
Open

nc-dirknilius wants to merge 1 commit into
aws-powertools:developfrom
nc-dirknilius:fix/s3-eventbridge-object-key

Conversation

@nc-dirknilius

@nc-dirknilius nc-dirknilius commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Issue number: closes #8901

Summary

Changes

S3EventBridgeNotificationEvent(...).detail.object.key applied unquote_plus to the key. S3 Event Notifications carry a URL-encoded key, but S3 events sent through EventBridge carry it unencoded. Decoding it altered keys containing + or a percent-encoded sequence. The key is now returned as is.

S3Event is unchanged. The docs page and its example don't mention the decoding, so they need no change.

References:

  • The S3 User Guide documents the encoding for S3 Event Notifications ("The object key name value is URL encoded"), but its EventBridge page doesn't mention any encoding.
  • Guidance for Media Lake on AWS: "EventBridge S3 notifications deliver the object key un-encoded (unlike classic S3 event notifications). It must be used as-is"
  • moto encodes the key for S3 Event Notifications, but not for EventBridge.

User experience

event.detail.object.key for an object in the bucket:

Object key Before After
a+b.txt a b.txt a+b.txt
a%20b.txt a b.txt a%20b.txt
folder name/ü (1).txt folder name/ü (1).txt unchanged

Compatibility (ADR 0006): this changes observable behavior, but only for keys containing + or a percent-encoded sequence. For those, the old value wasn't the key of the object, so reading it failed or returned a different object. Code that passes an already encoded key in a hand-written test event would notice the change.

Verification

  • Real event: an object with a space and a + in its key was uploaded to a bucket with EventBridge enabled. The event received by a Lambda function through an EventBridge rule contained the unencoded key (names replaced, other fields removed), and reading the object with the decoded key failed:

    {"detail-type": "Object Created", "detail": {"object": {"key": "folder name/a+b.txt"}}}
  • Tests: added a test with four keys. Two of them (a+b.txt, a%20b.txt) fail on develop, and all pass with the fix. uv run --locked pytest tests/unit/data_classes passes on Python 3.10 to 3.14.

  • ruff and mypy pass.

  • An AI assistant helped to write this PR and to run these checks.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

…events

S3 Event Notifications carry a URL-encoded object key, but S3 events sent
through EventBridge carry it unencoded. Decoding it altered keys containing
`+` or a percent-encoded sequence, e.g. `a+b.txt` became `a b.txt`.
@nc-dirknilius
nc-dirknilius requested a review from a team as a code owner November 24, 2026 13:31
@boring-cyborg boring-cyborg Bot added the tests label Nov 24, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 24, 2026
@sonarqubecloud

Copy link
Copy Markdown

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

size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: S3EventBridgeNotificationEvent URL-decodes object keys that are not encoded

1 participant