Update example to use new AWS Session
This commit is contained in:
parent
94f0b2ae1e
commit
4f374e4425
1 changed files with 13 additions and 21 deletions
|
|
@ -11,15 +11,13 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
||||||
|
alog "github.com/apex/log"
|
||||||
|
"github.com/apex/log/handlers/text"
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
"github.com/aws/aws-sdk-go/service/dynamodb"
|
"github.com/aws/aws-sdk-go/service/dynamodb"
|
||||||
"github.com/aws/aws-sdk-go/service/kinesis"
|
"github.com/aws/aws-sdk-go/service/kinesis"
|
||||||
|
|
||||||
alog "github.com/apex/log"
|
|
||||||
"github.com/apex/log/handlers/text"
|
|
||||||
|
|
||||||
consumer "github.com/harlow/kinesis-consumer"
|
consumer "github.com/harlow/kinesis-consumer"
|
||||||
checkpoint "github.com/harlow/kinesis-consumer/checkpoint/ddb"
|
checkpoint "github.com/harlow/kinesis-consumer/checkpoint/ddb"
|
||||||
)
|
)
|
||||||
|
|
@ -62,37 +60,31 @@ func main() {
|
||||||
)
|
)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Following will overwrite the default dynamodb client
|
sess, err := session.NewSession(aws.NewConfig())
|
||||||
// Older versions of aws sdk does not picking up aws config properly.
|
if err != nil {
|
||||||
// You probably need to update aws sdk verison. Tested the following with 1.13.59
|
log.Log("new session error: %v", err)
|
||||||
myDynamoDbClient := dynamodb.New(
|
}
|
||||||
session.New(aws.NewConfig()), &aws.Config{
|
|
||||||
Region: aws.String("us-west-2"),
|
// New Kinesis and DynamoDB clients (if you need custom config)
|
||||||
},
|
myKsis := kinesis.New(sess)
|
||||||
)
|
myDdbClient := dynamodb.New(sess)
|
||||||
|
|
||||||
// ddb checkpoint
|
// ddb checkpoint
|
||||||
ck, err := checkpoint.New(*app, *table, checkpoint.WithDynamoClient(myDynamoDbClient), checkpoint.WithRetryer(&MyRetryer{}))
|
ck, err := checkpoint.New(*app, *table, checkpoint.WithDynamoClient(myDdbClient), checkpoint.WithRetryer(&MyRetryer{}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log("checkpoint error: %v", err)
|
log.Log("checkpoint error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// expvar counter
|
||||||
var counter = expvar.NewMap("counters")
|
var counter = expvar.NewMap("counters")
|
||||||
|
|
||||||
// The following 2 lines will overwrite the default kinesis client
|
|
||||||
ksis := kinesis.New(
|
|
||||||
session.New(aws.NewConfig()), &aws.Config{
|
|
||||||
Region: aws.String("us-west-2"),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// consumer
|
// consumer
|
||||||
c, err := consumer.New(
|
c, err := consumer.New(
|
||||||
*stream,
|
*stream,
|
||||||
consumer.WithCheckpoint(ck),
|
consumer.WithCheckpoint(ck),
|
||||||
consumer.WithLogger(log),
|
consumer.WithLogger(log),
|
||||||
consumer.WithCounter(counter),
|
consumer.WithCounter(counter),
|
||||||
consumer.WithClient(ksis),
|
consumer.WithClient(myKsis),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log("consumer error: %v", err)
|
log.Log("consumer error: %v", err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue