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{}) }