Repository navigation
Bug: S3EventBridgeNotificationEvent URL-decodes object keys that are not encoded #8901
Description
Expected Behaviour
S3EventBridgeNotificationEvent(event).detail.object.key returns the key of the object, so it can be used to read the object.
Current Behaviour
The property applies unquote_plus to the key. S3 Event Notifications carry a URL-encoded key, but S3 events sent through EventBridge carry it unencoded. Keys containing + or a percent-encoded sequence are therefore altered: both a+b.txt and a%20b.txt become a b.txt. Reading the object then fails, or returns a different object if one exists under the altered key.
The S3 User Guide documents the encoding for S3 Event Notifications ("The object key name value is URL encoded"). Its EventBridge page doesn't mention any encoding. A real event contains the unencoded key, see the logs below.
Guidance for Media Lake on AWS describes the same: "EventBridge S3 notifications deliver the object key un-encoded (unlike classic S3 event notifications). It must be used as-is"
Code snippet
from aws_lambda_powertools.utilities.data_classes import S3EventBridgeNotificationEvent
event = {"detail": {"bucket": {"name": "my-bucket"}, "object": {"key": "folder name/a+b.txt"}}}
key = S3EventBridgeNotificationEvent(event).detail.object.key
print(key) # folder name/a b.txt
assert key == "folder name/a+b.txt"Possible Solution
Return self["key"] in S3EventBridgeNotificationObject.key. S3Event should stay as it is, because its keys are encoded.
I opened #8900 with this change and a test.
Steps to Reproduce
- Run the snippet above: the assertion fails.
To see the key in a real event:
- Enable Amazon EventBridge on an S3 bucket.
- Create a rule for
Object Createdevents of the bucket, with a Lambda function that logs the event as its target. - Upload an object with the key
folder name/a+b.txt. - The logged event has
"key": "folder name/a+b.txt"indetail.object, but the data class returnsfolder name/a b.txt.
Did you run the reproduction yourself?
Yes, I ran it and saw the failure
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.14
Packaging format used
PyPi
Debugging logs
Received event (names replaced, other fields removed):
{"detail-type": "Object Created", "detail": {"object": {"key": "folder name/a+b.txt"}}}
HeadObject with the decoded key (the function has no s3:ListBucket permission, so a missing object returns 403):
botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: ForbiddenMetadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsBacklog
Activity
powertools-for-aws-oss-automation commentedon Nov 24, 2026
Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out our GitHub Discussions: Join the conversation