From b5138e1372124c5ca2c3f4feff49dc2f85243292 Mon Sep 17 00:00:00 2001 From: MikiPWata <3Athlete.Gamer.Tr1@gmail.com> Date: Tue, 21 May 2024 17:12:35 +0900 Subject: [PATCH] S3: add EventBridge notification for delete object tagging --- moto/s3/models.py | 9 +++++ .../test_s3_eventbridge_integration.py | 35 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/moto/s3/models.py b/moto/s3/models.py index 1d23ca294331..6766283052f9 100644 --- a/moto/s3/models.py +++ b/moto/s3/models.py @@ -2673,8 +2673,17 @@ def delete_object_tagging( self, bucket_name: str, key_name: str, version_id: Optional[str] = None ) -> None: key = self.get_object(bucket_name, key_name, version_id=version_id) + bucket = self.get_bucket(bucket_name) + self.tagger.delete_all_tags_for_resource(key.arn) # type: ignore + notifications.send_event( + self.account_id, + notifications.S3NotificationEvent.OBJECT_TAGGING_DELETE_EVENT, + bucket, + key, + ) + def delete_object( self, bucket_name: str, diff --git a/tests/test_s3/test_s3_eventbridge_integration.py b/tests/test_s3/test_s3_eventbridge_integration.py index 8c1e3772fdac..61d2756a0c5b 100644 --- a/tests/test_s3/test_s3_eventbridge_integration.py +++ b/tests/test_s3/test_s3_eventbridge_integration.py @@ -292,3 +292,38 @@ def test_put_object_tagging_notification(): assert event_message["region"] == REGION_NAME assert event_message["detail"]["bucket"]["name"] == bucket_name assert event_message["detail"]["reason"] == "ObjectTagging" + + +@mock_aws +def test_delete_object_tagging_notification(): + resource_names = _seteup_bucket_notification_eventbridge() + bucket_name = resource_names["bucket_name"] + s3_client = boto3.client("s3", region_name=REGION_NAME) + + # Put Object + s3_client.put_object(Bucket=bucket_name, Key="keyname", Body="bodyofnewobject") + + # Put Object Tagging + s3_client.put_object_tagging( + Bucket=bucket_name, + Key="keyname", + Tagging={ + "TagSet": [ + {"Key": "item1", "Value": "foo"}, + {"Key": "item2", "Value": "bar"}, + ] + }, + ) + + # Delete Object Tagging + s3_client.delete_object_tagging(Bucket=bucket_name, Key="keyname") + + events = _get_send_events() + assert len(events) == 4 + event_message = json.loads(events[3]["message"]) + assert event_message["detail-type"] == "Object Tags Deleted" + assert event_message["source"] == "aws.s3" + assert event_message["account"] == ACCOUNT_ID + assert event_message["region"] == REGION_NAME + assert event_message["detail"]["bucket"]["name"] == bucket_name + assert event_message["detail"]["reason"] == "ObjectTagging"