kinesis-consumer/emitter/s3/emitter.go

46 lines
1.1 KiB
Go
Raw Normal View History

2016-02-09 03:39:09 +00:00
package s3
import (
"io"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
2016-05-01 17:42:28 +00:00
"github.com/aws/aws-sdk-go/service/s3"
)
2016-02-09 03:39:09 +00:00
// Emitter stores data in S3 bucket.
//
// The use of this struct requires the configuration of an S3 bucket/endpoint. When the buffer is full, this
// struct's Emit method adds the contents of the buffer to S3 as one file. The filename is generated
// from the first and last sequence numbers of the records contained in that file separated by a
// dash. This struct requires the configuration of an S3 bucket and endpoint.
2016-02-09 03:39:09 +00:00
type Emitter struct {
Bucket string
2016-05-01 17:42:28 +00:00
Region string
}
// Emit is invoked when the buffer is full. This method emits the set of filtered records.
2016-02-09 03:39:09 +00:00
func (e Emitter) Emit(s3Key string, b io.ReadSeeker) error {
2016-05-01 17:42:28 +00:00
svc := s3.New(
session.New(aws.NewConfig().WithMaxRetries(10)),
&aws.Config{
Region: aws.String(e.Region),
},
)
params := &s3.PutObjectInput{
Body: b,
Bucket: aws.String(e.Bucket),
ContentType: aws.String("text/plain"),
Key: aws.String(s3Key),
}
2016-05-01 17:42:28 +00:00
_, err := svc.PutObject(params)
if err != nil {
2016-02-09 03:39:09 +00:00
return err
}
2016-02-09 03:39:09 +00:00
return nil
}