2014-12-07 21:51:07 +00:00
|
|
|
package connector
|
|
|
|
|
|
|
|
|
|
import (
|
2016-02-03 05:04:22 +00:00
|
|
|
"io"
|
2015-05-26 04:51:53 +00:00
|
|
|
"os"
|
|
|
|
|
|
2016-02-03 05:04:22 +00:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws/session"
|
|
|
|
|
"github.com/aws/aws-sdk-go/service/kinesis"
|
2014-12-07 21:51:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// An implementation of Emitter that puts event data on S3 file, and then puts the
|
|
|
|
|
// S3 file path onto the output stream for processing by manifest application.
|
|
|
|
|
type S3ManifestEmitter struct {
|
|
|
|
|
OutputStream string
|
2016-02-03 05:04:22 +00:00
|
|
|
Bucket string
|
|
|
|
|
Prefix string
|
2014-12-07 21:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-03 05:04:22 +00:00
|
|
|
func (e S3ManifestEmitter) Emit(s3Key string, b io.ReadSeeker) {
|
|
|
|
|
// put contents to S3 Bucket
|
|
|
|
|
s3 := &S3Emitter{Bucket: e.Bucket}
|
|
|
|
|
s3.Emit(s3Key, b)
|
2014-12-07 21:51:07 +00:00
|
|
|
|
2016-02-03 05:04:22 +00:00
|
|
|
// put file path on Kinesis output stream
|
|
|
|
|
params := &kinesis.PutRecordInput{
|
|
|
|
|
Data: []byte(s3Key),
|
|
|
|
|
PartitionKey: aws.String(s3Key),
|
|
|
|
|
StreamName: aws.String(e.OutputStream),
|
|
|
|
|
}
|
2014-12-07 21:51:07 +00:00
|
|
|
|
2016-02-03 05:04:22 +00:00
|
|
|
svc := kinesis.New(session.New())
|
|
|
|
|
_, err := svc.PutRecord(params)
|
2014-12-07 21:51:07 +00:00
|
|
|
|
|
|
|
|
if err != nil {
|
2015-05-26 04:51:53 +00:00
|
|
|
logger.Log("error", "PutRecord", "msg", err)
|
|
|
|
|
os.Exit(1)
|
2014-12-07 21:51:07 +00:00
|
|
|
} else {
|
2016-02-03 05:04:22 +00:00
|
|
|
logger.Log("info", "S3ManifestEmitter", "stream", e.OutputStream, "key", s3Key)
|
2014-12-07 21:51:07 +00:00
|
|
|
}
|
|
|
|
|
}
|