Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[479] CloudWatchEvent renamed to EventBridgeEvent #537

Merged
merged 6 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions events/README_CloudWatch_Events.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Sample Function

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.
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.

mateusmarquezini marked this conversation as resolved.
Show resolved Hide resolved
```go
import (
Expand All @@ -11,7 +11,7 @@ import (
"github.com/aws/aws-lambda-go/events"
)

func handler(ctx context.Context, event events.CloudWatchEvent) {
func handler(ctx context.Context, event events.EventBridgeEvent) {
fmt.Printf("Detail = %s\n", event.Detail)
}
```
Expand Down
6 changes: 3 additions & 3 deletions events/cloudwatch_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"time"
)

// CloudWatchEvent is the outer structure of an event sent via CloudWatch Events.
// For examples of events that come via CloudWatch Events, see https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html
type CloudWatchEvent struct {
mateusmarquezini marked this conversation as resolved.
Show resolved Hide resolved
// EventBridgeEvent is the outer structure of an event sent via EventBridge serverless service.
// For examples of events that come via EventBridge, see https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html
type EventBridgeEvent struct {
Version string `json:"version"`
ID string `json:"id"`
DetailType string `json:"detail-type"`
Expand Down
4 changes: 2 additions & 2 deletions events/cloudwatch_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestCloudwatchScheduledEventIdempotency(t *testing.T) {
"\"resources\":[\"arn:aws:events:us-east-1:123456789012:rule/SampleRule\"]," +
"\"detail\":{}}")

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

func TestCloudwatchScheduledEventRequestMalformedJson(t *testing.T) {
test.TestMalformedJson(t, CloudWatchEvent{})
test.TestMalformedJson(t, EventBridgeEvent{})
}
36 changes: 18 additions & 18 deletions events/cloudwatch_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
"encoding/json"
)

// CloudwatchLogsEvent represents raw data from a cloudwatch logs event
mateusmarquezini marked this conversation as resolved.
Show resolved Hide resolved
type CloudwatchLogsEvent struct {
AWSLogs CloudwatchLogsRawData `json:"awslogs"`
// EventBridgeEventLogs represents raw data from an eventbridge logs event
type EventBridgeEventLogs struct {
AWSLogs EventBridgeLogsRawData `json:"awslogs"`
}

// CloudwatchLogsRawData contains gzipped base64 json representing the bulk
// of a cloudwatch logs event
type CloudwatchLogsRawData struct {
// EventBridgeLogsRawData contains gzipped base64 json representing the bulk
// of an eventbridge logs event
type EventBridgeLogsRawData struct {
Data string `json:"data"`
}

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

// CloudwatchLogsData is an unmarshal'd, ungzip'd, cloudwatch logs event
type CloudwatchLogsData struct {
Owner string `json:"owner"`
LogGroup string `json:"logGroup"`
LogStream string `json:"logStream"`
SubscriptionFilters []string `json:"subscriptionFilters"`
MessageType string `json:"messageType"`
LogEvents []CloudwatchLogsLogEvent `json:"logEvents"`
// EventBridgeLogsData is an unmarshal'd, ungzip'd, eventbridge logs event
type EventBridgeLogsData struct {
Owner string `json:"owner"`
LogGroup string `json:"logGroup"`
LogStream string `json:"logStream"`
SubscriptionFilters []string `json:"subscriptionFilters"`
MessageType string `json:"messageType"`
LogEvents []EventBridgeLogEvent `json:"logEvents"`
}

// CloudwatchLogsLogEvent represents a log entry from cloudwatch logs
type CloudwatchLogsLogEvent struct {
// EventBridgeLogEvent represents a log entry from eventbridge logs
type EventBridgeLogEvent struct {
ID string `json:"id"`
Timestamp int64 `json:"timestamp"`
Message string `json:"message"`
Expand Down
26 changes: 13 additions & 13 deletions events/cloudwatch_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (

func TestCloudwatchLogs(t *testing.T) {
for _, test := range []struct {
name string
eventJSON string
expectError bool
expectCloudwatchEventData CloudwatchLogsEvent
name string
eventJSON string
expectError bool
expectEventBridgeData EventBridgeEventLogs
}{
{"Well formed cloudwatch event",
"./testdata/cloudwatch-logs-event.json",
false,
CloudwatchLogsEvent{
AWSLogs: CloudwatchLogsRawData{
EventBridgeEventLogs{
AWSLogs: EventBridgeLogsRawData{
Data: "H4sIAAAAAAAAAHWPwQqCQBCGX0Xm7EFtK+smZBEUgXoLCdMhFtKV3akI8d0bLYmibvPPN3wz00CJxmQnTO41whwWQRIctmEcB6sQbFC3CjW3XW8kxpOpP+OC22d1Wml1qZkQGtoMsScxaczKN3plG8zlaHIta5KqWsozoTYw3/djzwhpLwivWFGHGpAFe7DL68JlBUk+l7KSN7tCOEJ4M3/qOI49vMHj+zCKdlFqLaU2ZHV2a4Ct/an0/ivdX8oYc1UVX860fQDQiMdxRQEAAA==",
},
},
Expand All @@ -29,7 +29,7 @@ func TestCloudwatchLogs(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
inputJSON := tst.ReadJSONFromFile(t, test.eventJSON)

var inputEvent CloudwatchLogsEvent
var inputEvent EventBridgeEventLogs
err := json.Unmarshal(inputJSON, &inputEvent)

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

if !reflect.DeepEqual(test.expectCloudwatchEventData, inputEvent) {
t.Errorf("expected: %+v, received: %v", test.expectCloudwatchEventData, inputEvent)
if !reflect.DeepEqual(test.expectEventBridgeData, inputEvent) {
t.Errorf("expected: %+v, received: %v", test.expectEventBridgeData, inputEvent)
}
})
}
Expand All @@ -52,20 +52,20 @@ func TestCloudwatchLogsParse(t *testing.T) {
name string
eventJSON string
expectError bool
expectCloudwatchLogsData CloudwatchLogsData
expectCloudwatchLogsData EventBridgeLogsData
}{
{"Well formed cloudwatch event",
"./testdata/cloudwatch-logs-event.json",
false,
CloudwatchLogsData{
EventBridgeLogsData{
Owner: "123456789123",
LogGroup: "testLogGroup",
LogStream: "testLogStream",
SubscriptionFilters: []string{
"testFilter",
},
MessageType: "DATA_MESSAGE",
LogEvents: []CloudwatchLogsLogEvent{
LogEvents: []EventBridgeLogEvent{
{ID: "eventId1", Timestamp: 1440442987000, Message: "[ERROR] First test message"},
{ID: "eventId2", Timestamp: 1440442987001, Message: "[ERROR], Second test message"},
},
Expand All @@ -76,7 +76,7 @@ func TestCloudwatchLogsParse(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
inputJSON := tst.ReadJSONFromFile(t, test.eventJSON)

var inputEvent CloudwatchLogsEvent
var inputEvent EventBridgeEventLogs
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion events/codedeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
)

// CodeDeployEvent is documented at:
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html#acd_event_types
// https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html#acd_event_types
type CodeDeployEvent struct {
// AccountID is the id of the AWS account from which the event originated.
AccountID string `json:"account"`
Expand Down
4 changes: 2 additions & 2 deletions events/codepipeline_cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const (
)

// CodePipelineEvent is documented at:
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html#codepipeline_event_type
type CodePipelineCloudWatchEvent struct {
// https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html#codepipeline_event_type
mateusmarquezini marked this conversation as resolved.
Show resolved Hide resolved
type CodePipelineEventBridgeEvent struct {
mateusmarquezini marked this conversation as resolved.
Show resolved Hide resolved
// Version is the version of the event's schema.
Version string `json:"version"`

Expand Down
13 changes: 7 additions & 6 deletions events/codepipeline_cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ package events

import (
"encoding/json"
"github.com/stretchr/testify/require"
"io/ioutil" //nolint: staticcheck
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestUnmarshalCodePipelineEvent(t *testing.T) {
tests := []struct {
input string
expect CodePipelineCloudWatchEvent
expect CodePipelineEventBridgeEvent
}{
{
input: "testdata/codepipeline-action-execution-stage-change-event.json",
expect: CodePipelineCloudWatchEvent{
expect: CodePipelineEventBridgeEvent{
Version: "0",
ID: "CWE-event-id",
DetailType: "CodePipeline Action Execution State Change",
Expand Down Expand Up @@ -45,7 +46,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
},
{
input: "testdata/codepipeline-execution-stage-change-event.json",
expect: CodePipelineCloudWatchEvent{
expect: CodePipelineEventBridgeEvent{
Version: "0",
ID: "CWE-event-id",
DetailType: "CodePipeline Stage Execution State Change",
Expand All @@ -66,7 +67,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
},
{
input: "testdata/codepipeline-execution-state-change-event.json",
expect: CodePipelineCloudWatchEvent{
expect: CodePipelineEventBridgeEvent{
Version: "0",
ID: "CWE-event-id",
DetailType: "CodePipeline Pipeline Execution State Change",
Expand All @@ -91,7 +92,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
data, err := ioutil.ReadFile(testcase.input)
require.NoError(t, err)

var actual CodePipelineCloudWatchEvent
var actual CodePipelineEventBridgeEvent
require.NoError(t, json.Unmarshal(data, &actual))

require.Equal(t, testcase.expect, actual)
Expand Down
Loading