Skip to content

Commit 379b423

Browse files
author
Patrick Robinson
committed
Configure dynamo throughput
Default to pay per request allow configuring provisioned throughput
1 parent 469ad86 commit 379b423

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

checkpointer.go

+19-9
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ var ErrSequenceIDNotFound = errors.New("SequenceIDNotFoundForShard")
3535

3636
// DynamoCheckpoint implements the Checkpoint interface using DynamoDB as a backend
3737
type DynamoCheckpoint struct {
38-
TableName string
39-
LeaseDuration int
40-
Retries int
41-
svc dynamodbiface.DynamoDBAPI
42-
skipTableCheck bool
38+
TableName string
39+
LeaseDuration int
40+
Retries int
41+
ReadCapacityUnits *int64
42+
WriteCapacityUnits *int64
43+
BillingMode *string
44+
svc dynamodbiface.DynamoDBAPI
45+
skipTableCheck bool
4346
}
4447

4548
// Init initialises the DynamoDB Checkpoint
@@ -68,6 +71,10 @@ func (checkpointer *DynamoCheckpoint) Init() error {
6871
checkpointer.LeaseDuration = defaultLeaseDuration
6972
}
7073

74+
if checkpointer.BillingMode == nil {
75+
checkpointer.BillingMode = aws.String("PAY_PER_REQUEST")
76+
}
77+
7178
if !checkpointer.skipTableCheck && !checkpointer.doesTableExist() {
7279
return checkpointer.createTable()
7380
}
@@ -217,18 +224,21 @@ func (checkpointer *DynamoCheckpoint) createTable() error {
217224
AttributeType: aws.String("S"),
218225
},
219226
},
227+
BillingMode: checkpointer.BillingMode,
220228
KeySchema: []*dynamodb.KeySchemaElement{
221229
{
222230
AttributeName: aws.String("ShardID"),
223231
KeyType: aws.String("HASH"),
224232
},
225233
},
226-
ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
227-
ReadCapacityUnits: aws.Int64(1),
228-
WriteCapacityUnits: aws.Int64(1),
229-
},
230234
TableName: aws.String(checkpointer.TableName),
231235
}
236+
if *checkpointer.BillingMode == "PROVISIONED" {
237+
input.ProvisionedThroughput = &dynamodb.ProvisionedThroughput{
238+
ReadCapacityUnits: checkpointer.ReadCapacityUnits,
239+
WriteCapacityUnits: checkpointer.WriteCapacityUnits,
240+
}
241+
}
232242
_, err := checkpointer.svc.CreateTable(input)
233243
return err
234244
}

consumer.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ type KinesisConsumer struct {
5252
StreamName string
5353
ShardIteratorType string
5454
RecordConsumer RecordConsumer
55-
TableName string
5655
EmptyRecordBackoffMs int
5756
LeaseDuration int
5857
Monitoring MonitoringConfiguration
5958
DisableAutomaticCheckpoints bool
6059
Retries *int
60+
TableName string
61+
DynamoReadCapacityUnits *int64
62+
DynamoWriteCapacityUnits *int64
63+
DynamoBillingMode *string
6164
svc kinesisiface.KinesisAPI
6265
checkpointer Checkpointer
6366
stop *chan struct{}
@@ -106,9 +109,12 @@ func (kc *KinesisConsumer) StartConsumer() error {
106109
}
107110
kc.svc = kinesis.New(session)
108111
kc.checkpointer = &DynamoCheckpoint{
109-
TableName: kc.TableName,
110-
Retries: retries,
111-
LeaseDuration: kc.LeaseDuration,
112+
ReadCapacityUnits: kc.DynamoReadCapacityUnits,
113+
WriteCapacityUnits: kc.DynamoWriteCapacityUnits,
114+
BillingMode: kc.DynamoBillingMode,
115+
TableName: kc.TableName,
116+
Retries: retries,
117+
LeaseDuration: kc.LeaseDuration,
112118
}
113119
}
114120

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module github.com/patrobinson/gokini
22

33
require (
4-
github.com/aws/aws-sdk-go v1.15.78
4+
github.com/aws/aws-sdk-go v1.19.38
55
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect
66
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 // indirect
77
github.com/gogo/protobuf v1.1.1 // indirect

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/aws/aws-sdk-go v1.15.78 h1:LaXy6lWR0YK7LKyuU0QWy2ws/LWTPfYV/UgfiBu4tvY=
22
github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
3+
github.com/aws/aws-sdk-go v1.19.38 h1:WKjobgPO4Ua1ww2NJJl2/zQNreUZxvqmEzwMlRjjm9g=
4+
github.com/aws/aws-sdk-go v1.19.38/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
35
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
46
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
57
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 h1:SKI1/fuSdodxmNNyVBR8d7X/HuLnRpvvFO0AgyQk764=
@@ -14,6 +16,8 @@ github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA=
1416
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1517
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 h1:12VvqtR6Aowv3l/EQUlocDHW2Cp4G9WJVH7uyH8QFJE=
1618
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
19+
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
20+
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
1721
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
1822
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
1923
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2 h1:JAEbJn3j/FrhdWA9jW8B5ajsLIjeuEHLi8xE4fk997o=

0 commit comments

Comments
 (0)