-
-
Save StevenACoffman/d95dada61d615f3ff8fc68ad063541e4 to your computer and use it in GitHub Desktop.
Golang + Kinesis 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 ( | |
"log" | |
"encoding/json" | |
"fmt" | |
"os" | |
"math/rand" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/firehose" | |
) | |
// FakeEntity is just used for testing purposes | |
type FakeEntity struct { | |
ID int `json:"id"` | |
Name string `json:"name"` | |
Description string `json:"description"` | |
} | |
const maxUint = 4294967295 | |
func main() { | |
log.Println("Begin") | |
streamName := "firehoseStream" | |
sess := session.Must(session.NewSession()) | |
// Create a Firehose client with additional configuration | |
firehoseService := firehose.New(sess, aws.NewConfig().WithRegion("us-east-1")) | |
recordsBatchInput := &firehose.PutRecordBatchInput{} | |
recordsBatchInput = recordsBatchInput.SetDeliveryStreamName(streamName) | |
records := []*firehose.Record{} | |
for i := 0; i < 10; i++ { | |
data := FakeEntity{ | |
ID: rand.Intn(maxUint), | |
Name: fmt.Sprintf("Name-%d", rand.Intn(maxUint)), | |
Description: fmt.Sprintf("Test-Description %d", rand.Intn(maxUint)), | |
} | |
b, err := json.Marshal(data) | |
if err != nil { | |
log.Printf("Error: %v", err) | |
os.Exit(1) | |
} | |
record := &firehose.Record{Data: b} | |
records = append(records, record) | |
} | |
recordsBatchInput = recordsBatchInput.SetRecords(records) | |
resp, err := firehoseService.PutRecordBatch(recordsBatchInput) | |
if err != nil { | |
fmt.Printf("PutRecordBatch err: %v\n", err) | |
} else { | |
fmt.Printf("PutRecordBatch: %v\n", resp) | |
} | |
log.Println("Done") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment