5
5
"os"
6
6
7
7
"github.com/aws/aws-sdk-go-v2/aws"
8
- "github.com/aws/aws-sdk-go-v2/config"
9
8
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
10
9
11
10
"github.com/ahamlinman/randomizer/internal/awsconfig"
@@ -18,13 +17,17 @@ import (
18
17
// AWS configuration is read as described at
19
18
// https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html.
20
19
func FactoryFromEnv (ctx context.Context ) (func (string ) randomizer.Store , error ) {
21
- cfg , err := awsConfigFromEnv (ctx )
20
+ cfg , err := awsconfig . New (ctx )
22
21
if err != nil {
23
22
return nil , err
24
23
}
25
24
26
- db := dynamodb .NewFromConfig (cfg )
27
25
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
+ })
28
31
29
32
return func (partition string ) randomizer.Store {
30
33
store , err := New (db , table , partition )
@@ -35,21 +38,6 @@ func FactoryFromEnv(ctx context.Context) (func(string) randomizer.Store, error)
35
38
}, nil
36
39
}
37
40
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
-
53
41
func tableFromEnv () string {
54
42
if table := os .Getenv ("DYNAMODB_TABLE" ); table != "" {
55
43
return table
0 commit comments