Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamoDB Deprecation Fixes #4534

Merged
merged 4 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions physical/dynamodb/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ func NewDynamoDBBackend(conf map[string]string, logger log.Logger) (physical.Bac
Transport: pooledTransport,
}).
WithMaxRetries(dynamodbMaxRetry)
client := dynamodb.New(session.New(awsConf))

awsSession, err := session.NewSession(awsConf)
if err != nil {
return nil, errwrap.Wrapf("Could not establish AWS session: {{err}}", err)
}

client := dynamodb.New(awsSession)

if err := ensureTableExists(client, table, readCapacity, writeCapacity); err != nil {
return nil, err
Expand Down Expand Up @@ -259,7 +265,7 @@ func (d *DynamoDBBackend) Put(ctx context.Context, entry *physical.Entry) error
Key: recordKeyForVaultKey(entry.Key),
Value: entry.Value,
}
item, err := dynamodbattribute.ConvertToMap(record)
item, err := dynamodbattribute.MarshalMap(record)
if err != nil {
return errwrap.Wrapf("could not convert prefix record to DynamoDB item: {{err}}", err)
}
Expand All @@ -274,7 +280,7 @@ func (d *DynamoDBBackend) Put(ctx context.Context, entry *physical.Entry) error
Path: recordPathForVaultKey(prefix),
Key: fmt.Sprintf("%s/", recordKeyForVaultKey(prefix)),
}
item, err := dynamodbattribute.ConvertToMap(record)
item, err := dynamodbattribute.MarshalMap(record)
if err != nil {
return errwrap.Wrapf("could not convert prefix record to DynamoDB item: {{err}}", err)
}
Expand Down Expand Up @@ -311,7 +317,7 @@ func (d *DynamoDBBackend) Get(ctx context.Context, key string) (*physical.Entry,
}

record := &DynamoDBRecord{}
if err := dynamodbattribute.ConvertFromMap(resp.Item, record); err != nil {
if err := dynamodbattribute.UnmarshalMap(resp.Item, record); err != nil {
return nil, err
}

Expand Down Expand Up @@ -385,7 +391,7 @@ func (d *DynamoDBBackend) List(ctx context.Context, prefix string) ([]string, er
err := d.client.QueryPages(queryInput, func(out *dynamodb.QueryOutput, lastPage bool) bool {
var record DynamoDBRecord
for _, item := range out.Items {
dynamodbattribute.ConvertFromMap(item, &record)
dynamodbattribute.UnmarshalMap(item, &record)
if !strings.HasPrefix(record.Key, DynamoDBLockPrefix) {
keys = append(keys, record.Key)
}
Expand Down Expand Up @@ -697,8 +703,8 @@ func ensureTableExists(client *dynamodb.DynamoDB, table string, readCapacity, wr
_, err := client.DescribeTable(&dynamodb.DescribeTableInput{
TableName: aws.String(table),
})
if awserr, ok := err.(awserr.Error); ok {
if awserr.Code() == "ResourceNotFoundException" {
if awsError, ok := err.(awserr.Error); ok {
if awsError.Code() == "ResourceNotFoundException" {
_, err = client.CreateTable(&dynamodb.CreateTableInput{
TableName: aws.String(table),
ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
Expand Down
18 changes: 14 additions & 4 deletions physical/dynamodb/dynamodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ func TestDynamoDBBackend(t *testing.T) {
region = "us-east-1"
}

conn := dynamodb.New(session.New(&aws.Config{
awsSession, err := session.NewSession(&aws.Config{
Credentials: credsProvider,
Endpoint: aws.String(endpoint),
Region: aws.String(region),
}))
})
if err != nil {
t.Fatalf("err: %v", err)
}

conn := dynamodb.New(awsSession)

var randInt = rand.New(rand.NewSource(time.Now().UnixNano())).Int()
table := fmt.Sprintf("vault-dynamodb-testacc-%d", randInt)
Expand Down Expand Up @@ -80,11 +85,16 @@ func TestDynamoDBHABackend(t *testing.T) {
region = "us-east-1"
}

conn := dynamodb.New(session.New(&aws.Config{
awsSession, err := session.NewSession(&aws.Config{
Credentials: credsProvider,
Endpoint: aws.String(endpoint),
Region: aws.String(region),
}))
})
if err != nil {
t.Fatalf("err: %v", err)
}

conn := dynamodb.New(awsSession)

var randInt = rand.New(rand.NewSource(time.Now().UnixNano())).Int()
table := fmt.Sprintf("vault-dynamodb-testacc-%d", randInt)
Expand Down