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

Add AWS_DYNAMODB_REGION Environment variable #15054

Merged
merged 4 commits into from
Apr 28, 2022
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
3 changes: 3 additions & 0 deletions changelog/15054.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:feature
storage/dynamodb: Added `AWS_DYNAMODB_REGION` environment variable.
```
11 changes: 7 additions & 4 deletions physical/dynamodb/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,16 @@ func NewDynamoDBBackend(conf map[string]string, logger log.Logger) (physical.Bac
if endpoint == "" {
endpoint = conf["endpoint"]
}
region := os.Getenv("AWS_REGION")
region := os.Getenv("AWS_DYNAMODB_REGION")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swenson I wonder if using a switch is cleaner instead of deep nesting. I know that we have this pattern for the other config params, but since we're evaluating several env vars for this one it might not be a bad idea?

	var region string
	switch {
	case os.Getenv("AWS_DYNAMODB_REGION") != "":
		region = os.Getenv("AWS_DYNAMODB_REGION")
	case os.Getenv("AWS_REGION") != "":
		region = os.Getenv("AWS_REGION")
	case os.Getenv("AWS_DEFAULT_REGION") != "":
		region = os.Getenv("AWS_DEFAULT_REGION")
	case conf["region"] != "":
		region = conf["region"]
	default:
		region = DefaultDynamoDBRegion
	}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I was thinking that the deep nesting was a little bit much. The switch is much cleaner.

if region == "" {
region = os.Getenv("AWS_DEFAULT_REGION")
region = os.Getenv("AWS_REGION")
if region == "" {
region = conf["region"]
region = os.Getenv("AWS_DEFAULT_REGION")
if region == "" {
region = DefaultDynamoDBRegion
region = conf["region"]
if region == "" {
region = DefaultDynamoDBRegion
}
}
}
}
Expand Down