-
-
Save StevenACoffman/123b58d68364c3bdc49a4cd9d2727c22 to your computer and use it in GitHub Desktop.
Golang lambda function to send Streams data to Firehose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/apex/go-apex" | |
"github.com/apex/go-apex/kinesis" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/firehose" | |
) | |
const ( | |
deliveryStreamName = "HarlowTest" | |
maxBatchSize = 400 | |
) | |
func main() { | |
kinesis.HandleFunc(func(event *kinesis.Event, ctx *apex.Context) error { | |
svc := firehose.New(session.New()) | |
records := make([]*firehose.Record, 0, maxBatchSize) | |
numRecords := len(event.Records) | |
for i, r := range event.Records { | |
records = append( | |
records, | |
&firehose.Record{Data: append(r.Kinesis.Data, '\n')}, | |
) | |
if len(records) == maxBatchSize || i == (numRecords-1) { | |
_, err := svc.PutRecordBatch( | |
&firehose.PutRecordBatchInput{ | |
DeliveryStreamName: aws.String(deliveryStreamName), | |
Records: records, | |
}, | |
) | |
if err != nil { | |
return err | |
} | |
records = records[:0] | |
} | |
} | |
return nil | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment