From b5b7267d297de263cc5b61f8c37543daa9c95ffd Mon Sep 17 00:00:00 2001 From: Andrew Babichev Date: Wed, 23 Oct 2019 15:48:54 +0300 Subject: [PATCH] Add CloudWatch README (#242) * Add CloudWatch README * Update README_CloudWatch_Events.md * Update README_CloudWatch_Logs.md --- 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..2c6bb53b --- /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..75a219e0 --- /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) + } +} +```