@@ -18,9 +18,8 @@ import (
18
18
"github.com/aws/aws-sdk-go/aws/awserr"
19
19
"github.com/aws/aws-sdk-go/aws/client"
20
20
"github.com/aws/aws-sdk-go/aws/credentials"
21
- "github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
22
21
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
23
- "github.com/aws/aws-sdk-go/aws/ec2metadata "
22
+ "github.com/aws/aws-sdk-go/aws/defaults "
24
23
"github.com/aws/aws-sdk-go/aws/request"
25
24
"github.com/aws/aws-sdk-go/aws/session"
26
25
"github.com/aws/aws-sdk-go/service/s3"
@@ -574,10 +573,6 @@ func (s *S3) session() (*session.Session, error) {
574
573
))
575
574
}
576
575
577
- providers = append (providers , & ec2rolecreds.EC2RoleProvider {
578
- Client : ec2metadata .New (awsSession ),
579
- })
580
-
581
576
httpClient := & http.Client {}
582
577
if s .opts .InsecureSkipTLSVerify {
583
578
httpClient = & http.Client {
@@ -587,15 +582,21 @@ func (s *S3) session() (*session.Session, error) {
587
582
}
588
583
}
589
584
590
- return session . NewSession ( & aws.Config {
585
+ cfg := & aws.Config {
591
586
Region : aws .String (s .opts .Region ),
592
587
Endpoint : aws .String (s .opts .EndpointURL ),
593
- Credentials : credentials .NewChainCredentials (providers ),
594
588
S3ForcePathStyle : s .opts .ForcePathStyle ,
595
589
HTTPClient : httpClient ,
596
590
LogLevel : aws .LogLevel (SDKLogLevel (s .opts .DebugLogLevels , nil )),
597
591
Logger : awsLogger (s .log ),
598
- })
592
+ }
593
+
594
+ // fetch credentials from remote endpoints like EC2 or ECS roles
595
+ providers = append (providers , defaults .RemoteCredProvider (* cfg , defaults .Handlers ()))
596
+
597
+ cfg .Credentials = credentials .NewChainCredentials (providers )
598
+
599
+ return session .NewSession (cfg )
599
600
}
600
601
601
602
func awsLogger (l log.LogEvent ) aws.Logger {
0 commit comments