From 16fde0e12cd24118c542dd24cad7d8a595a5c39b Mon Sep 17 00:00:00 2001 From: Alessandro Lattao Date: Thu, 22 Oct 2026 10:02:18 +0200 Subject: [PATCH] Add ReplayName to CloudWatchEvent EventBridge adds a replay-name field to every event it replays from an archive. CloudWatchEvent had no field for it, so a handler could not tell a replayed event from a live one. The field is omitempty, so an event that was not replayed marshals to the same JSON as before. Fixes #651 --- events/cloudwatch_events.go | 1 + events/cloudwatch_events_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/events/cloudwatch_events.go b/events/cloudwatch_events.go index 0b109ba3..4be055bc 100644 --- a/events/cloudwatch_events.go +++ b/events/cloudwatch_events.go @@ -16,6 +16,7 @@ type CloudWatchEvent struct { Region string `json:"region"` Resources []string `json:"resources"` Detail json.RawMessage `json:"detail"` + ReplayName string `json:"replay-name,omitempty"` // set only on events replayed from an archive } type EventBridgeEvent = CloudWatchEvent diff --git a/events/cloudwatch_events_test.go b/events/cloudwatch_events_test.go index c364bb86..3d8bf432 100644 --- a/events/cloudwatch_events_test.go +++ b/events/cloudwatch_events_test.go @@ -31,6 +31,31 @@ func TestCloudwatchScheduledEventIdempotency(t *testing.T) { assert.JSONEq(t, string(inputJSON), string(outputJSON)) } +func TestCloudwatchReplayedEventIdempotency(t *testing.T) { + inputJSON := []byte( + "{\"version\":\"0\",\"id\":\"890abcde-f123-4567-890a-bcdef1234567\"," + + "\"detail-type\":\"Scheduled Event\",\"source\":\"aws.events\"," + + "\"account\":\"123456789012\",\"time\":\"2016-12-30T18:44:49Z\"," + + "\"region\":\"us-east-1\"," + + "\"resources\":[\"arn:aws:events:us-east-1:123456789012:rule/SampleRule\"]," + + "\"detail\":{},\"replay-name\":\"my-replay\"}") + + var inputEvent CloudWatchEvent + err := json.Unmarshal(inputJSON, &inputEvent) + if err != nil { + t.Errorf("Could not unmarshal replayed event: %v", err) + } + + assert.Equal(t, "my-replay", inputEvent.ReplayName) + + outputJSON, err := json.Marshal(inputEvent) + if err != nil { + t.Errorf("Could not marshal replayed event: %v", err) + } + + assert.JSONEq(t, string(inputJSON), string(outputJSON)) +} + func TestCloudwatchScheduledEventRequestMalformedJson(t *testing.T) { test.TestMalformedJson(t, &CloudWatchEvent{}) }