Skip to content

Commit 476d4f7

Browse files
committed
Migrate to non-deprecated DynamoDB endpoint setup
The per-AWS-client endpoint configuration is deprecated in favor of specifying this on individual service clients.
1 parent 6607634 commit 476d4f7

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

internal/store/dynamodb/factory.go

+6-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"os"
66

77
"github.com/aws/aws-sdk-go-v2/aws"
8-
"github.com/aws/aws-sdk-go-v2/config"
98
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
109

1110
"github.com/ahamlinman/randomizer/internal/awsconfig"
@@ -18,13 +17,17 @@ import (
1817
// AWS configuration is read as described at
1918
// https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html.
2019
func FactoryFromEnv(ctx context.Context) (func(string) randomizer.Store, error) {
21-
cfg, err := awsConfigFromEnv(ctx)
20+
cfg, err := awsconfig.New(ctx)
2221
if err != nil {
2322
return nil, err
2423
}
2524

26-
db := dynamodb.NewFromConfig(cfg)
2725
table := tableFromEnv()
26+
db := dynamodb.NewFromConfig(cfg, func(opts *dynamodb.Options) {
27+
if endpoint := os.Getenv("DYNAMODB_ENDPOINT"); endpoint != "" {
28+
opts.BaseEndpoint = aws.String(endpoint)
29+
}
30+
})
2831

2932
return func(partition string) randomizer.Store {
3033
store, err := New(db, table, partition)
@@ -35,21 +38,6 @@ func FactoryFromEnv(ctx context.Context) (func(string) randomizer.Store, error)
3538
}, nil
3639
}
3740

38-
func awsConfigFromEnv(ctx context.Context) (aws.Config, error) {
39-
var extraOptions []awsconfig.Option
40-
if endpoint := os.Getenv("DYNAMODB_ENDPOINT"); endpoint != "" {
41-
extraOptions = append(extraOptions,
42-
config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(
43-
func(_, _ string, _ ...any) (aws.Endpoint, error) {
44-
return aws.Endpoint{URL: endpoint}, nil
45-
},
46-
)),
47-
)
48-
}
49-
50-
return awsconfig.New(ctx, extraOptions...)
51-
}
52-
5341
func tableFromEnv() string {
5442
if table := os.Getenv("DYNAMODB_TABLE"); table != "" {
5543
return table

0 commit comments

Comments
 (0)