Skip to content
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

Conversation

tsugumi-sys
Copy link
Contributor

Sending a notification when an object is uploaded to S3 via POST request.

related: #7363

Copy link
Collaborator

@bblommers bblommers left a 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"})

@@ -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,
Copy link
Collaborator

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.

Copy link
Contributor Author

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:
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

@bblommers bblommers left a 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:

new_key = self.backend.put_object(bucket_name, key, f)

@tsugumi-sys
Copy link
Contributor Author

tsugumi-sys commented Feb 27, 2024

hmmm, I don't understand why the tests failed?
https://github.com/getmoto/moto/actions/runs/8058630565/job/22011891131?pr=7368
https://github.com/getmoto/moto/actions/runs/8058630565/job/22011891477?pr=7368

I tried to reproduce the error in my local computer, but the tests were passed :(

@bblommers
Copy link
Collaborator

@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!

@bblommers bblommers added this to the 5.0.3 milestone Feb 28, 2024
@bblommers bblommers merged commit ee9cdfa into getmoto:master Feb 28, 2024
35 of 37 checks passed
Copy link
Contributor

This is now part of moto >= 5.0.3.dev30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants