@@ -42,21 +42,8 @@ type Cloud interface {
42
42
43
43
// NewCloud constructs new Cloud implementation.
44
44
func NewCloud (cfg CloudConfig , metricsRegisterer prometheus.Registerer ) (Cloud , error ) {
45
- sess := session .Must (session .NewSession (aws .NewConfig ()))
46
- injectUserAgent (& sess .Handlers )
47
- metadata := services .NewEC2Metadata (sess )
48
- if cfg .ThrottleConfig != nil {
49
- throttler := throttle .NewThrottler (cfg .ThrottleConfig )
50
- throttler .InjectHandlers (& sess .Handlers )
51
- }
52
- if metricsRegisterer != nil {
53
- metricsCollector , err := metrics .NewCollector (metricsRegisterer )
54
- if err != nil {
55
- return nil , errors .Wrapf (err , "failed to initialize sdk metrics collector" )
56
- }
57
- metricsCollector .InjectHandlers (& sess .Handlers )
58
- }
59
-
45
+ metadataSess := session .Must (session .NewSession (aws .NewConfig ()))
46
+ metadata := services .NewEC2Metadata (metadataSess )
60
47
if len (cfg .Region ) == 0 {
61
48
region , err := metadata .Region ()
62
49
if err != nil {
@@ -74,7 +61,21 @@ func NewCloud(cfg CloudConfig, metricsRegisterer prometheus.Registerer) (Cloud,
74
61
}
75
62
76
63
awsCFG := aws .NewConfig ().WithRegion (cfg .Region ).WithSTSRegionalEndpoint (endpoints .RegionalSTSEndpoint ).WithMaxRetries (cfg .MaxRetries )
77
- sess = session .Must (session .NewSession (awsCFG ))
64
+ sess := session .Must (session .NewSession (awsCFG ))
65
+ injectUserAgent (& sess .Handlers )
66
+
67
+ if cfg .ThrottleConfig != nil {
68
+ throttler := throttle .NewThrottler (cfg .ThrottleConfig )
69
+ throttler .InjectHandlers (& sess .Handlers )
70
+ }
71
+ if metricsRegisterer != nil {
72
+ metricsCollector , err := metrics .NewCollector (metricsRegisterer )
73
+ if err != nil {
74
+ return nil , errors .Wrapf (err , "failed to initialize sdk metrics collector" )
75
+ }
76
+ metricsCollector .InjectHandlers (& sess .Handlers )
77
+ }
78
+
78
79
return & defaultCloud {
79
80
cfg : cfg ,
80
81
ec2 : services .NewEC2 (sess ),
0 commit comments