From dd44d9adc58563edb464051db55cc4c8aea66934 Mon Sep 17 00:00:00 2001 From: Andrew Babichev Date: Fri, 18 Oct 2019 22:57:23 +0300 Subject: [PATCH 1/3] Add CloudWatch README --- events/README.md | 4 ++++ events/README_CloudWatch_Events.md | 17 +++++++++++++++++ events/README_CloudWatch_Logs.md | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 events/README_CloudWatch_Events.md create mode 100644 events/README_CloudWatch_Logs.md diff --git a/events/README.md b/events/README.md index d1a50f92..5c3ccdc9 100644 --- a/events/README.md +++ b/events/README.md @@ -14,6 +14,10 @@ This package provides input types for Lambda functions that process AWS events. [CloudFormation Events](../cfn/README.md) +[CloudWatch Events](README_CloudWatch_Events.md) + +[CloudWatch Logs](README_CloudWatch_Logs.md) + [Chime Bot Events](README_Chime_Bots.md) [Code Commit Events](README_CodeCommit.md) diff --git a/events/README_CloudWatch_Events.md b/events/README_CloudWatch_Events.md new file mode 100644 index 00000000..fb894f15 --- /dev/null +++ b/events/README_CloudWatch_Events.md @@ -0,0 +1,17 @@ + +# 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. + +```go +import ( + "context" + "fmt" + + "github.com/aws/aws-lambda-go/events" +) + +func handler(ctx context.Context, event events.CloudWatchEvent) { + fmt.Printf("Detail = %s\n", event.Detail) +} +``` diff --git a/events/README_CloudWatch_Logs.md b/events/README_CloudWatch_Logs.md new file mode 100644 index 00000000..98d228c7 --- /dev/null +++ b/events/README_CloudWatch_Logs.md @@ -0,0 +1,20 @@ + +# Sample Function + +The following is a Lambda function that receives Amazon CloudWatch Logs event record data as input and writes message part to Lambda's CloudWatch Logs. Note that by default anything written to Console will be logged as CloudWatch Logs events. + +```go +import ( + "context" + "fmt" + + "github.com/aws/aws-lambda-go/events" +) + +func handler(ctx context.Context, logsEvent events.CloudwatchLogsEvent) { + data, _ := logsEvent.AWSLogs.Parse() + for _, logEvent := range data.LogEvents { + fmt.Printf("Message = %s\n", logEvent.Message) + } +} +``` From 8dc52019f4e357a6885f275694a611d934193621 Mon Sep 17 00:00:00 2001 From: Bryan Moffatt Date: Tue, 22 Oct 2019 09:35:10 +0100 Subject: [PATCH 2/3] Update README_CloudWatch_Events.md --- events/README_CloudWatch_Events.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/events/README_CloudWatch_Events.md b/events/README_CloudWatch_Events.md index fb894f15..2c6bb53b 100644 --- a/events/README_CloudWatch_Events.md +++ b/events/README_CloudWatch_Events.md @@ -12,6 +12,6 @@ import ( ) func handler(ctx context.Context, event events.CloudWatchEvent) { - fmt.Printf("Detail = %s\n", event.Detail) + fmt.Printf("Detail = %s\n", event.Detail) } ``` From 0e6d43c823388c018ebbb5051e7a6afa67a693ae Mon Sep 17 00:00:00 2001 From: Bryan Moffatt Date: Tue, 22 Oct 2019 09:35:52 +0100 Subject: [PATCH 3/3] Update README_CloudWatch_Logs.md --- events/README_CloudWatch_Logs.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/events/README_CloudWatch_Logs.md b/events/README_CloudWatch_Logs.md index 98d228c7..75a219e0 100644 --- a/events/README_CloudWatch_Logs.md +++ b/events/README_CloudWatch_Logs.md @@ -12,9 +12,9 @@ import ( ) func handler(ctx context.Context, logsEvent events.CloudwatchLogsEvent) { - data, _ := logsEvent.AWSLogs.Parse() - for _, logEvent := range data.LogEvents { - fmt.Printf("Message = %s\n", logEvent.Message) - } + data, _ := logsEvent.AWSLogs.Parse() + for _, logEvent := range data.LogEvents { + fmt.Printf("Message = %s\n", logEvent.Message) + } } ```