-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
S3: Sending notification to EventBridge ObjectCreated:Post
#7368
S3: Sending notification to EventBridge ObjectCreated:Post
#7368
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm reading the documentation right, the POST object
-event only happens for a regular HTTP POST request. It looks like your test verifies the CompeteMultiPart-action, which is a separate event.
From the docs:
The POST operation adds an object to a specified bucket by using HTML forms. [...] Parameters are passed [...] as form fields to POST in the multipart/form-data encoded message body.
So in normal language (i.e., Python code):
requests.post(f"https://{bucket_name}.s3.amazonaws.com/", {"key": "key2", "file": "nothing"})
moto/s3/responses.py
Outdated
@@ -2259,6 +2259,7 @@ def _key_response_post( | |||
multipart=multipart, | |||
encryption=multipart.sse_encryption, | |||
kms_key_id=multipart.kms_key_id, | |||
request_method=request.method, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would send a POST
event immediately after the CompleteMultipartUpload
-action is finished. If I understand it correctly, AWS will only send a single event in this case. So we should avoid sending a POST
event completely here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's true, thanks!
|
||
|
||
@mock_aws | ||
def test_pub_object_notification(): | ||
def test_put_object_notification_ObjectCreated_PUT(): | ||
if not settings.TEST_DECORATOR_MODE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason behind skipping the tests in ServerMode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this part was added by mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the part of the code where we handle a multipart/formdata POST request, and where we should send an event:
Line 1119 in ce07482
new_key = self.backend.put_object(bucket_name, key, f) |
hmmm, I don't understand why the tests failed? I tried to reproduce the error in my local computer, but the tests were passed :( |
@tsugumi-sys Looks like that's a issue specific to Python 3.11 and up. When Moto reads a file from a form-upload, it doesn't close the stream. I guess it is closed automatically in older versions of Python, somehow. I've opened #7405 with a fix - once that's merged, I'll merge this one as well. Thank you for the PR! |
This is now part of moto >= 5.0.3.dev30 |
Sending a notification when an object is uploaded to S3 via POST request.
related: #7363