-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
56 lines (47 loc) · 1.49 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package ssm
import (
"context"
"os"
"github.com/alexfalkowski/go-service/transport/http"
"github.com/alexfalkowski/go-service/transport/http/metrics/prometheus"
"github.com/alexfalkowski/go-service/transport/http/trace/opentracing"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ssm"
"go.uber.org/fx"
"go.uber.org/zap"
)
// ConfigParams for SSM.
type ClientParams struct {
fx.In
HTTPConfig *http.Config
Logger *zap.Logger
Tracer opentracing.Tracer
Metrics *prometheus.ClientMetrics
}
// NewClient for SSM.
func NewClient(params ClientParams) (*ssm.Client, error) {
client := http.NewClient(
http.ClientParams{Config: params.HTTPConfig},
http.WithClientLogger(params.Logger), http.WithClientTracer(params.Tracer),
http.WithClientMetrics(params.Metrics),
)
ctx := context.Background()
resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...any) (aws.Endpoint, error) {
url := os.Getenv("AWS_URL")
if url != "" {
return aws.Endpoint{PartitionID: "aws", URL: url, SigningRegion: region}, nil
}
return aws.Endpoint{}, &aws.EndpointNotFoundError{}
})
opts := []func(*config.LoadOptions) error{
config.WithEndpointResolverWithOptions(resolver),
config.WithHTTPClient(client),
config.WithRetryMaxAttempts(int(params.HTTPConfig.Retry.Attempts)),
}
cfg, err := config.LoadDefaultConfig(ctx, opts...)
if err != nil {
return nil, err
}
return ssm.NewFromConfig(cfg), nil
}