Skip to content

Commit 5dde5d7

Browse files
committed
add go snippet for lambda-kinesis
1 parent 218e553 commit 5dde5d7

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

integration-kinesis-to-lambda/main.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/aws/aws-lambda-go/events"
8+
"github.com/aws/aws-lambda-go/lambda"
9+
)
10+
11+
func handler(ctx context.Context, kinesisEvent events.KinesisEvent) error {
12+
if len(kinesisEvent.Records) == 0 {
13+
log.Printf("empty Kinesis event received")
14+
return nil
15+
}
16+
17+
for _, record := range kinesisEvent.Records {
18+
log.Printf("processed Kinesis event with EventId: %v", record.EventID)
19+
recordDataBytes := record.Kinesis.Data
20+
recordDataText := string(recordDataBytes)
21+
log.Printf("record data: %v", recordDataText)
22+
// TODO: Do interesting work based on the new data
23+
}
24+
log.Printf("successfully processed %v records", len(kinesisEvent.Records))
25+
return nil
26+
}
27+
28+
func main() {
29+
lambda.Start(handler)
30+
}

integration-kinesis-to-lambda/snippet-data.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@
5252
"language": "dotnet"
5353
}
5454
]
55+
},
56+
{
57+
"id": "Go",
58+
"title": "Usage Example with Go:",
59+
"description": "Consuming Kinesis event with Lambda using Go without batch item handling.",
60+
"snippets": [
61+
{
62+
"snippetPath": "main.go",
63+
"language": "go"
64+
}
65+
]
5566
}
5667
]
5768
}

0 commit comments

Comments
 (0)