8000 randomly generate request-id for S3 notification events (#7523) · localstack/localstack@4dd88e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4dd88e6

Browse files
authored
randomly generate request-id for S3 notification events (#7523)
1 parent 555b5a0 commit 4dd88e6

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

localstack/services/s3/notifications.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
TopicArn,
2929
TopicConfiguration,
3030
)
31+
from localstack.aws.protocol.serializer import gen_amzn_requestid_long
3132
from localstack.config import DEFAULT_REGION
3233
from localstack.services.s3.models import get_moto_s3_backend
3334
from localstack.services.s3.utils import (
@@ -456,7 +457,7 @@ def _get_event_payload(
456457
"etag": ctx.key_etag,
457458
"sequencer": "0062E99A88DC407460",
458459
},
459-
"request-id": "RKREYG1RN2X92YX6",
460+
"request-id": gen_amzn_requestid_long(),
460461
"requester": "074255357339",
461462
"source-ip-address": "127.0.0.1",
462463
# TODO previously headers.get("X-Forwarded-For", "127.0.0.1").split(",")[0]

localstack/services/s3/s3_listener.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from localstack import config, constants
2323
from localstack.aws.api import CommonServiceException
24+
from localstack.aws.protocol.serializer import gen_amzn_requestid_long
2425
from localstack.config import get_protocol as get_service_protocol
2526
from localstack.services.generic_proxy import ProxyListener
2627
from localstack.services.generic_proxy import append_cors_headers as _append_default_cors_headers
@@ -251,7 +252,7 @@ def get_event_message(
251252
"userIdentity": {"principalId": "AIDAJDPLRKLG7UEXAMPLE"},
252253
"requestParameters": {"sourceIPAddress": source_ip},
253254
"responseElements": {
254-
"x-amz-request-id": short_uid(),
255+
"x-amz-request-id": gen_amzn_requestid_long(),
255256
"x-amz-id-2": "eftixk72aD6Ap51TnqcoF8eFidJG9Z/2", # Amazon S3 host that processed the request
256257
},
257258
"s3": {
@@ -419,7 +420,7 @@ def send_notification_for_subscriber(
419420
"etag": object_data.get("ETag", ""),
420421
"sequencer": "0062E99A88DC407460",
421422
},
422-
"request-id": "RKREYG1RN2X92YX6",
423+
"request-id": gen_amzn_requestid_long(),
423424
"requester": "074255357339",
424425
"source-ip-address": source_ip,
425426
},

tests/integration/s3/test_s3_notifications_eventbridge.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,17 @@ def _receive_messages():
121121

122122
retries = 10 if is_aws_cloud() else 5
123123
retry(_receive_messages, retries=retries)
124-
125-
snapshot.match("object_deleted", messages.get("Object Deleted"))
126-
snapshot.match("object_created", messages.get("Object Created"))
124+
object_deleted_event = messages["Object Deleted"]
125+
object_created_event = messages["Object Created"]
126+
snapshot.match("object_deleted", object_deleted_event)
127+
snapshot.match("object_created", object_created_event)
128+
# assert that the request-id is randomly generated
129+
# ideally, it should use the true request-id. However, the request-id is set in the serializer for now,
130+
# and would need to be set before going through the skeleton
131+
assert (
132+
object_deleted_event["detail"]["request-id"]
133+
!= object_created_event["detail"]["request-id"]
134+
)
127135

128136
@pytest.mark.aws_validated
129137
@pytest.mark.skipif(condition=LEGACY_S3_PROVIDER, reason="not implemented")

0 commit comments

Comments
 (0)
0