Skip to content

Commit

Permalink
env_aws: Disable Retries and set Session cfg (#6860)
Browse files Browse the repository at this point in the history
env_aws: Disable Retries and set Session cfg
  • Loading branch information
endocrimes authored Dec 16, 2019
2 parents 2cdb89b + 59eb882 commit acde3e1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions client/fingerprint/env_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ func (f *EnvAWSFingerprint) Fingerprint(request *FingerprintRequest, response *F
timeout = 1 * time.Millisecond
}

ec2meta := ec2MetaClient(f.endpoint, timeout)
ec2meta, err := ec2MetaClient(f.endpoint, timeout)
if err != nil {
return fmt.Errorf("failed to setup ec2Metadata client: %v", err)
}

if !ec2meta.Available() {
return nil
Expand Down Expand Up @@ -191,15 +194,20 @@ func (f *EnvAWSFingerprint) linkSpeed(ec2meta *ec2metadata.EC2Metadata) int {
return netSpeed
}

func ec2MetaClient(endpoint string, timeout time.Duration) *ec2metadata.EC2Metadata {
func ec2MetaClient(endpoint string, timeout time.Duration) (*ec2metadata.EC2Metadata, error) {
client := &http.Client{
Timeout: timeout,
Transport: cleanhttp.DefaultTransport(),
}

c := aws.NewConfig().WithHTTPClient(client)
c := aws.NewConfig().WithHTTPClient(client).WithMaxRetries(0)
if endpoint != "" {
c = c.WithEndpoint(endpoint)
}
return ec2metadata.New(session.New(), c)

session, err := session.NewSession(c)
if err != nil {
return nil, err
}
return ec2metadata.New(session, c), nil
}

0 comments on commit acde3e1

Please sign in to comment.