Skip to content

Commit 19047df

Browse files
snufkinbmoffatt
authored andcommitted
Add Kinesis Data Analytics example (#221)
1 parent f7dba3f commit 19047df

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

events/README_KinesisDataAnalytics.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Sample function
2+
3+
The following is an example for an Application Destination Lambda function that receives Amazon Kinesis Data Analytics event records as an input. To send Kinesis Data Analytics output records the Lamdbda function must be compliant with the (required input and return data models)[https://docs.aws.amazon.com/kinesisanalytics/latest/dev/how-it-works-output-lambda.html], so the handler returns a list of delivery statuses for each record.
4+
5+
The following Lambda function receives Amazon Kinesis Data Analytics event record data as an input and writes some of the record data to CloudWatch Logs. For each entry it adds an element to the response slice, marking it delivered. When the logic considers the delivery to be failed the `events.KinesisAnalyticsOutputDeliveryFailed` value should be used for the response `Result` field.
6+
7+
8+
```go
9+
package main
10+
11+
import (
12+
"context"
13+
"encoding/json"
14+
"fmt"
15+
"log"
16+
17+
"github.com/aws/aws-lambda-go/events"
18+
"github.com/aws/aws-lambda-go/lambda"
19+
)
20+
21+
func handler(ctx context.Context, kinesisAnalyticsEvent events.KinesisAnalyticsOutputDeliveryEvent) (events.KinesisAnalyticsOutputDeliveryResponse, error) {
22+
var err error
23+
24+
var responses events.KinesisAnalyticsOutputDeliveryResponse
25+
responses.Records = make([]events.KinesisAnalyticsOutputDeliveryResponseRecord, len(kinesisAnalyticsEvent.Records))
26+
27+
for i, record := range kinesisAnalyticsEvent.Records {
28+
responses.Records[i] = events.KinesisAnalyticsOutputDeliveryResponseRecord{
29+
RecordID: record.RecordID,
30+
Result: events.KinesisAnalyticsOutputDeliveryOK,
31+
}
32+
33+
dataBytes := record.Data
34+
dataText := string(dataBytes)
35+
36+
fmt.Printf("%s Data = %s \n", record.RecordID, dataText)
37+
}
38+
return responses, err
39+
}
40+
41+
func main() {
42+
lambda.Start(handler)
43+
}
44+
45+
```

0 commit comments

Comments
 (0)