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.
2019func 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-
5341func tableFromEnv () string {
5442 if table := os .Getenv ("DYNAMODB_TABLE" ); table != "" {
5543 return table
0 commit comments