-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
59 lines (50 loc) · 1.73 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
57
58
59
package ssm
import (
"context"
"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/credentials"
"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
Config *Config
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()
region := params.Config.Region
resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...any) (aws.Endpoint, error) {
if params.Config.URL != "" {
return aws.Endpoint{PartitionID: "aws", URL: params.Config.URL, SigningRegion: region}, nil
}
return aws.Endpoint{}, &aws.EndpointNotFoundError{}
})
opts := []func(*config.LoadOptions) error{
config.WithRegion(region),
config.WithEndpointResolverWithOptions(resolver),
config.WithHTTPClient(client),
config.WithRetryMaxAttempts(int(params.HTTPConfig.Retry.Attempts)),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(params.Config.Access, params.Config.Secret, "")),
}
cfg, err := config.LoadDefaultConfig(ctx, opts...)
if err != nil {
return nil, err
}
return ssm.NewFromConfig(cfg), nil
}