Add configuration options for AWS service endpoints (#5)
* Add configuration options for AWS service endpoints Signed-off-by: Timothy Studd <tim@goguardian.com> * Fix KCL naming consistency issue Signed-off-by: Timothy Studd <tim@goguardian.com>
This commit is contained in:
parent
03685b2b19
commit
cd343cca09
4 changed files with 38 additions and 10 deletions
|
|
@ -158,6 +158,14 @@ type (
|
||||||
// ApplicationName is name of application. Kinesis allows multiple applications to consume the same stream.
|
// ApplicationName is name of application. Kinesis allows multiple applications to consume the same stream.
|
||||||
ApplicationName string
|
ApplicationName string
|
||||||
|
|
||||||
|
// DynamoDBEndpoint is an optional endpoint URL that overrides the default generated endpoint for a DynamoDB client.
|
||||||
|
// If this is empty, the default generated endpoint will be used.
|
||||||
|
DynamoDBEndpoint string
|
||||||
|
|
||||||
|
// KinesisEndpoint is an optional endpoint URL that overrides the default generated endpoint for a Kinesis client.
|
||||||
|
// If this is empty, the default generated endpoint will be used.
|
||||||
|
KinesisEndpoint string
|
||||||
|
|
||||||
// TableName is name of the dynamo db table for managing kinesis stream default to ApplicationName
|
// TableName is name of the dynamo db table for managing kinesis stream default to ApplicationName
|
||||||
TableName string
|
TableName string
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,9 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/vmware/vmware-go-kcl/clientlibrary/utils"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/vmware/vmware-go-kcl/clientlibrary/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewKinesisClientLibConfig to create a default KinesisClientLibConfiguration based on the required fields.
|
// NewKinesisClientLibConfig to create a default KinesisClientLibConfiguration based on the required fields.
|
||||||
|
|
@ -77,6 +78,18 @@ func NewKinesisClientLibConfig(applicationName, streamName, regionName, workerID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithKinesisEndpoint is used to provide an alternative Kinesis endpoint
|
||||||
|
func (c *KinesisClientLibConfiguration) WithKinesisEndpoint(kinesisEndpoint string) *KinesisClientLibConfiguration {
|
||||||
|
c.KinesisEndpoint = kinesisEndpoint
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithDynamoDBEndpoint is used to provide an alternative DynamoDB endpoint
|
||||||
|
func (c *KinesisClientLibConfiguration) WithDynamoDBEndpoint(dynamoDBEndpoint string) *KinesisClientLibConfiguration {
|
||||||
|
c.DynamoDBEndpoint = dynamoDBEndpoint
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
// WithTableName to provide alternative lease table in DynamoDB
|
// WithTableName to provide alternative lease table in DynamoDB
|
||||||
func (c *KinesisClientLibConfiguration) WithTableName(tableName string) *KinesisClientLibConfiguration {
|
func (c *KinesisClientLibConfiguration) WithTableName(tableName string) *KinesisClientLibConfiguration {
|
||||||
c.TableName = tableName
|
c.TableName = tableName
|
||||||
|
|
|
||||||
|
|
@ -29,13 +29,14 @@ package worker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"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"
|
||||||
|
|
@ -112,11 +113,17 @@ func NewWorker(factory kcl.IRecordProcessorFactory, kclConfig *config.KinesisCli
|
||||||
|
|
||||||
// create session for Kinesis
|
// create session for Kinesis
|
||||||
log.Info("Creating Kinesis session")
|
log.Info("Creating Kinesis session")
|
||||||
s := session.New(&aws.Config{Region: aws.String(w.regionName)})
|
s := session.New(&aws.Config{
|
||||||
|
Region: aws.String(w.regionName),
|
||||||
|
Endpoint: &kclConfig.KinesisEndpoint,
|
||||||
|
})
|
||||||
w.kc = kinesis.New(s)
|
w.kc = kinesis.New(s)
|
||||||
|
|
||||||
log.Info("Creating DynamoDB session")
|
log.Info("Creating DynamoDB session")
|
||||||
s = session.New(&aws.Config{Region: aws.String(w.regionName)})
|
s = session.New(&aws.Config{
|
||||||
|
Region: aws.String(w.regionName),
|
||||||
|
Endpoint: &kclConfig.DynamoDBEndpoint,
|
||||||
|
})
|
||||||
w.dynamo = dynamodb.New(s)
|
w.dynamo = dynamodb.New(s)
|
||||||
w.checkpointer = NewDynamoCheckpoint(w.dynamo, kclConfig)
|
w.checkpointer = NewDynamoCheckpoint(w.dynamo, kclConfig)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue