Skip to content

Commit 532af4b

Browse files
aws#479 CloudWatchEvent renamed to EventBridgeEvent
1 parent 752114b commit 532af4b

8 files changed

+47
-46
lines changed

events/README_CloudWatch_Events.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Sample Function
33

4-
The following is a Lambda function that receives Amazon CloudWatch event record data as input and writes event detail to Lambda's CloudWatch Logs. Note that by default anything written to Console will be logged as CloudWatch Logs events.
4+
The following is a Lambda function that receives Amazon EventBridge event record data as input and writes event detail to Lambda's CloudWatch Logs. Note that by default anything written to Console will be logged as CloudWatch Logs events.
55

66
```go
77
import (
@@ -11,7 +11,7 @@ import (
1111
"github.com/aws/aws-lambda-go/events"
1212
)
1313

14-
func handler(ctx context.Context, event events.CloudWatchEvent) {
14+
func handler(ctx context.Context, event events.EventBridgeEvent) {
1515
fmt.Printf("Detail = %s\n", event.Detail)
1616
}
1717
```

events/cloudwatch_events.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"time"
66
)
77

8-
// CloudWatchEvent is the outer structure of an event sent via CloudWatch Events.
9-
// For examples of events that come via CloudWatch Events, see https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html
10-
type CloudWatchEvent struct {
8+
// EventBridgeEvent is the outer structure of an event sent via EventBridge serverless service.
9+
// For examples of events that come via EventBridge, see https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html
10+
type EventBridgeEvent struct {
1111
Version string `json:"version"`
1212
ID string `json:"id"`
1313
DetailType string `json:"detail-type"`

events/cloudwatch_events_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestCloudwatchScheduledEventIdempotency(t *testing.T) {
1717
"\"resources\":[\"arn:aws:events:us-east-1:123456789012:rule/SampleRule\"]," +
1818
"\"detail\":{}}")
1919

20-
var inputEvent CloudWatchEvent
20+
var inputEvent EventBridgeEvent
2121
err := json.Unmarshal(inputJSON, &inputEvent)
2222
if err != nil {
2323
t.Errorf("Could not unmarshal scheduled event: %v", err)
@@ -32,5 +32,5 @@ func TestCloudwatchScheduledEventIdempotency(t *testing.T) {
3232
}
3333

3434
func TestCloudwatchScheduledEventRequestMalformedJson(t *testing.T) {
35-
test.TestMalformedJson(t, CloudWatchEvent{})
35+
test.TestMalformedJson(t, EventBridgeEvent{})
3636
}

events/cloudwatch_logs.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import (
77
"encoding/json"
88
)
99

10-
// CloudwatchLogsEvent represents raw data from a cloudwatch logs event
11-
type CloudwatchLogsEvent struct {
12-
AWSLogs CloudwatchLogsRawData `json:"awslogs"`
10+
// EventBridgeEventLogs represents raw data from an eventbridge logs event
11+
type EventBridgeEventLogs struct {
12+
AWSLogs EventBridgeLogsRawData `json:"awslogs"`
1313
}
1414

15-
// CloudwatchLogsRawData contains gzipped base64 json representing the bulk
16-
// of a cloudwatch logs event
17-
type CloudwatchLogsRawData struct {
15+
// EventBridgeLogsRawData contains gzipped base64 json representing the bulk
16+
// of an eventbridge logs event
17+
type EventBridgeLogsRawData struct {
1818
Data string `json:"data"`
1919
}
2020

21-
// Parse returns a struct representing a usable CloudwatchLogs event
22-
func (c CloudwatchLogsRawData) Parse() (d CloudwatchLogsData, err error) {
21+
// Parse returns a struct representing a usable EventBridgeLogs event
22+
func (c EventBridgeLogsRawData) Parse() (d EventBridgeLogsData, err error) {
2323
data, err := base64.StdEncoding.DecodeString(c.Data)
2424
if err != nil {
2525
return
@@ -37,18 +37,18 @@ func (c CloudwatchLogsRawData) Parse() (d CloudwatchLogsData, err error) {
3737
return
3838
}
3939

40-
// CloudwatchLogsData is an unmarshal'd, ungzip'd, cloudwatch logs event
41-
type CloudwatchLogsData struct {
42-
Owner string `json:"owner"`
43-
LogGroup string `json:"logGroup"`
44-
LogStream string `json:"logStream"`
45-
SubscriptionFilters []string `json:"subscriptionFilters"`
46-
MessageType string `json:"messageType"`
47-
LogEvents []CloudwatchLogsLogEvent `json:"logEvents"`
40+
// EventBridgeLogsData is an unmarshal'd, ungzip'd, eventbridge logs event
41+
type EventBridgeLogsData struct {
42+
Owner string `json:"owner"`
43+
LogGroup string `json:"logGroup"`
44+
LogStream string `json:"logStream"`
45+
SubscriptionFilters []string `json:"subscriptionFilters"`
46+
MessageType string `json:"messageType"`
47+
LogEvents []EventBridgeLogEvent `json:"logEvents"`
4848
}
4949

50-
// CloudwatchLogsLogEvent represents a log entry from cloudwatch logs
51-
type CloudwatchLogsLogEvent struct {
50+
// EventBridgeLogEvent represents a log entry from eventbridge logs
51+
type EventBridgeLogEvent struct {
5252
ID string `json:"id"`
5353
Timestamp int64 `json:"timestamp"`
5454
Message string `json:"message"`

events/cloudwatch_logs_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import (
1010

1111
func TestCloudwatchLogs(t *testing.T) {
1212
for _, test := range []struct {
13-
name string
14-
eventJSON string
15-
expectError bool
16-
expectCloudwatchEventData CloudwatchLogsEvent
13+
name string
14+
eventJSON string
15+
expectError bool
16+
expectEventBridgeData EventBridgeEventLogs
1717
}{
1818
{"Well formed cloudwatch event",
1919
"./testdata/cloudwatch-logs-event.json",
2020
false,
21-
CloudwatchLogsEvent{
22-
AWSLogs: CloudwatchLogsRawData{
21+
EventBridgeEventLogs{
22+
AWSLogs: EventBridgeLogsRawData{
2323
Data: "H4sIAAAAAAAAAHWPwQqCQBCGX0Xm7EFtK+smZBEUgXoLCdMhFtKV3akI8d0bLYmibvPPN3wz00CJxmQnTO41whwWQRIctmEcB6sQbFC3CjW3XW8kxpOpP+OC22d1Wml1qZkQGtoMsScxaczKN3plG8zlaHIta5KqWsozoTYw3/djzwhpLwivWFGHGpAFe7DL68JlBUk+l7KSN7tCOEJ4M3/qOI49vMHj+zCKdlFqLaU2ZHV2a4Ct/an0/ivdX8oYc1UVX860fQDQiMdxRQEAAA==",
2424
},
2525
},
@@ -29,7 +29,7 @@ func TestCloudwatchLogs(t *testing.T) {
2929
t.Run(test.name, func(t *testing.T) {
3030
inputJSON := tst.ReadJSONFromFile(t, test.eventJSON)
3131

32-
var inputEvent CloudwatchLogsEvent
32+
var inputEvent EventBridgeEventLogs
3333
err := json.Unmarshal(inputJSON, &inputEvent)
3434

3535
if err != nil && !test.expectError {
@@ -40,8 +40,8 @@ func TestCloudwatchLogs(t *testing.T) {
4040
t.Errorf("expected parse error")
4141
}
4242

43-
if !reflect.DeepEqual(test.expectCloudwatchEventData, inputEvent) {
44-
t.Errorf("expected: %+v, received: %v", test.expectCloudwatchEventData, inputEvent)
43+
if !reflect.DeepEqual(test.expectEventBridgeData, inputEvent) {
44+
t.Errorf("expected: %+v, received: %v", test.expectEventBridgeData, inputEvent)
4545
}
4646
})
4747
}
@@ -52,20 +52,20 @@ func TestCloudwatchLogsParse(t *testing.T) {
5252
name string
5353
eventJSON string
5454
expectError bool
55-
expectCloudwatchLogsData CloudwatchLogsData
55+
expectCloudwatchLogsData EventBridgeLogsData
5656
}{
5757
{"Well formed cloudwatch event",
5858
"./testdata/cloudwatch-logs-event.json",
5959
false,
60-
CloudwatchLogsData{
60+
EventBridgeLogsData{
6161
Owner: "123456789123",
6262
LogGroup: "testLogGroup",
6363
LogStream: "testLogStream",
6464
SubscriptionFilters: []string{
6565
"testFilter",
6666
},
6767
MessageType: "DATA_MESSAGE",
68-
LogEvents: []CloudwatchLogsLogEvent{
68+
LogEvents: []EventBridgeLogEvent{
6969
{ID: "eventId1", Timestamp: 1440442987000, Message: "[ERROR] First test message"},
7070
{ID: "eventId2", Timestamp: 1440442987001, Message: "[ERROR], Second test message"},
7171
},
@@ -76,7 +76,7 @@ func TestCloudwatchLogsParse(t *testing.T) {
7676
t.Run(test.name, func(t *testing.T) {
7777
inputJSON := tst.ReadJSONFromFile(t, test.eventJSON)
7878

79-
var inputEvent CloudwatchLogsEvent
79+
var inputEvent EventBridgeEventLogs
8080
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
8181
t.Errorf("could not unmarshal event. details: %v", err)
8282
}

events/codedeploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
)
2222

2323
// CodeDeployEvent is documented at:
24-
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html#acd_event_types
24+
// https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html#acd_event_types
2525
type CodeDeployEvent struct {
2626
// AccountID is the id of the AWS account from which the event originated.
2727
AccountID string `json:"account"`

events/codepipeline_cloudwatch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const (
4343

4444
// CodePipelineEvent is documented at:
4545
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html#codepipeline_event_type
46-
type CodePipelineCloudWatchEvent struct {
46+
type CodePipelineEventBridgeEvent struct {
4747
// Version is the version of the event's schema.
4848
Version string `json:"version"`
4949

events/codepipeline_cloudwatch_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ package events
22

33
import (
44
"encoding/json"
5-
"github.com/stretchr/testify/require"
65
"io/ioutil" //nolint: staticcheck
76
"testing"
87
"time"
8+
9+
"github.com/stretchr/testify/require"
910
)
1011

1112
func TestUnmarshalCodePipelineEvent(t *testing.T) {
1213
tests := []struct {
1314
input string
14-
expect CodePipelineCloudWatchEvent
15+
expect CodePipelineEventBridgeEvent
1516
}{
1617
{
1718
input: "testdata/codepipeline-action-execution-stage-change-event.json",
18-
expect: CodePipelineCloudWatchEvent{
19+
expect: CodePipelineEventBridgeEvent{
1920
Version: "0",
2021
ID: "CWE-event-id",
2122
DetailType: "CodePipeline Action Execution State Change",
@@ -45,7 +46,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
4546
},
4647
{
4748
input: "testdata/codepipeline-execution-stage-change-event.json",
48-
expect: CodePipelineCloudWatchEvent{
49+
expect: CodePipelineEventBridgeEvent{
4950
Version: "0",
5051
ID: "CWE-event-id",
5152
DetailType: "CodePipeline Stage Execution State Change",
@@ -66,7 +67,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
6667
},
6768
{
6869
input: "testdata/codepipeline-execution-state-change-event.json",
69-
expect: CodePipelineCloudWatchEvent{
70+
expect: CodePipelineEventBridgeEvent{
7071
Version: "0",
7172
ID: "CWE-event-id",
7273
DetailType: "CodePipeline Pipeline Execution State Change",
@@ -91,7 +92,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
9192
data, err := ioutil.ReadFile(testcase.input)
9293
require.NoError(t, err)
9394

94-
var actual CodePipelineCloudWatchEvent
95+
var actual CodePipelineEventBridgeEvent
9596
require.NoError(t, json.Unmarshal(data, &actual))
9697

9798
require.Equal(t, testcase.expect, actual)

0 commit comments

Comments
 (0)