Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Golang lambda function to send Streams data to Firehose
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
You can’t perform that action at this time.