Skip to content

Commit

Permalink
Reuse config in DynamoDb client
Browse files Browse the repository at this point in the history
  • Loading branch information
brikis98 committed Jun 3, 2016
1 parent 1656e2c commit 1164d39
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
13 changes: 4 additions & 9 deletions dynamodb/dynamo_lock_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func getAttribute(item map[string]*dynamodb.AttributeValue, attribute string) (s

// Create a DynamoDB item for the given item id. This item represents a lock and will include metadata about the
// current user, who is trying to acquire the lock.
func createItem(itemId string, awsRegion string) (map[string]*dynamodb.AttributeValue, error) {
iamUsername, err := getIamUsername(awsRegion)
func createItemAttributes(itemId string, client *dynamodb.DynamoDB) (map[string]*dynamodb.AttributeValue, error) {
iamUsername, err := getIamUsername(client)
if err != nil {
return nil, err
}
Expand All @@ -109,13 +109,8 @@ func createItem(itemId string, awsRegion string) (map[string]*dynamodb.Attribute
}

// Return the IAM username of the currently logged in user
func getIamUsername(awsRegion string) (string, error) {
config, err := createAwsConfig(awsRegion)
if err != nil {
return "", err
}

iamClient := iam.New(session.New(), config)
func getIamUsername(client *dynamodb.DynamoDB) (string, error) {
iamClient := iam.New(session.New(), &client.Config)
output, err := iamClient.GetUser(&iam.GetUserInput{})
if err != nil {
return "", errors.WithStackTrace(err)
Expand Down
2 changes: 1 addition & 1 deletion dynamodb/dynamo_lock_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func removeItemFromLockTable(itemId string, tableName string, client *dynamodb.D

// Write the given item to the DynamoDB lock table. If the given item already exists, return an error.
func writeItemToLockTable(itemId string, tableName string, client *dynamodb.DynamoDB) error {
item, err := createItem(itemId, *client.Config.Region)
item, err := createItemAttributes(itemId, client)
if err != nil {
return err
}
Expand Down

0 comments on commit 1164d39

Please sign in to comment.