@@ -174,7 +174,6 @@ const (
174
174
175
175
// Options provides the means to control how a Session is created and what
176
176
// configuration values will be loaded.
177
- //
178
177
type Options struct {
179
178
// Provides config values for the SDK to use when creating service clients
180
179
// and making API requests to services. Any value set in with this field
@@ -322,24 +321,24 @@ type Options struct {
322
321
// credentials file. Enabling the Shared Config will also allow the Session
323
322
// to be built with retrieving credentials with AssumeRole set in the config.
324
323
//
325
- // // Equivalent to session.New
326
- // sess := session.Must(session.NewSessionWithOptions(session.Options{}))
324
+ // // Equivalent to session.New
325
+ // sess := session.Must(session.NewSessionWithOptions(session.Options{}))
327
326
//
328
- // // Specify profile to load for the session's config
329
- // sess := session.Must(session.NewSessionWithOptions(session.Options{
330
- // Profile: "profile_name",
331
- // }))
327
+ // // Specify profile to load for the session's config
328
+ // sess := session.Must(session.NewSessionWithOptions(session.Options{
329
+ // Profile: "profile_name",
330
+ // }))
332
331
//
333
- // // Specify profile for config and region for requests
334
- // sess := session.Must(session.NewSessionWithOptions(session.Options{
335
- // Config: aws.Config{Region: aws.String("us-east-1")},
336
- // Profile: "profile_name",
337
- // }))
332
+ // // Specify profile for config and region for requests
333
+ // sess := session.Must(session.NewSessionWithOptions(session.Options{
334
+ // Config: aws.Config{Region: aws.String("us-east-1")},
335
+ // Profile: "profile_name",
336
+ // }))
338
337
//
339
- // // Force enable Shared Config support
340
- // sess := session.Must(session.NewSessionWithOptions(session.Options{
341
- // SharedConfigState: session.SharedConfigEnable,
342
- // }))
338
+ // // Force enable Shared Config support
339
+ // sess := session.Must(session.NewSessionWithOptions(session.Options{
340
+ // SharedConfigState: session.SharedConfigEnable,
341
+ // }))
343
342
func NewSessionWithOptions (opts Options ) (* Session , error ) {
344
343
var envCfg envConfig
345
344
var err error
@@ -375,7 +374,7 @@ func NewSessionWithOptions(opts Options) (*Session, error) {
375
374
// This helper is intended to be used in variable initialization to load the
376
375
// Session and configuration at startup. Such as:
377
376
//
378
- // var sess = session.Must(session.NewSession())
377
+ // var sess = session.Must(session.NewSession())
379
378
func Must (sess * Session , err error ) * Session {
380
379
if err != nil {
381
380
panic (err )
@@ -780,16 +779,6 @@ func mergeConfigSrcs(cfg, userCfg *aws.Config,
780
779
cfg .EndpointResolver = wrapEC2IMDSEndpoint (cfg .EndpointResolver , ec2IMDSEndpoint , endpointMode )
781
780
}
782
781
783
- // Configure credentials if not already set by the user when creating the
784
- // Session.
785
- if cfg .Credentials == credentials .AnonymousCredentials && userCfg .Credentials == nil {
786
- creds , err := resolveCredentials (cfg , envCfg , sharedCfg , handlers , sessOpts )
787
- if err != nil {
788
- return err
789
- }
790
- cfg .Credentials = creds
791
- }
792
-
793
782
cfg .S3UseARNRegion = userCfg .S3UseARNRegion
794
783
if cfg .S3UseARNRegion == nil {
795
784
cfg .S3UseARNRegion = & envCfg .S3UseARNRegion
@@ -812,6 +801,17 @@ func mergeConfigSrcs(cfg, userCfg *aws.Config,
812
801
}
813
802
}
814
803
804
+ // Configure credentials if not already set by the user when creating the Session.
805
+ // Credentials are resolved last such that all _resolved_ config values are propagated to credential providers.
806
+ // ticket: P83606045
807
+ if cfg .Credentials == credentials .AnonymousCredentials && userCfg .Credentials == nil {
808
+ creds , err := resolveCredentials (cfg , envCfg , sharedCfg , handlers , sessOpts )
809
+ if err != nil {
810
+ return err
811
+ }
812
+ cfg .Credentials = creds
813
+ }
814
+
815
815
return nil
816
816
}
817
817
@@ -845,8 +845,8 @@ func initHandlers(s *Session) {
845
845
// and handlers. If any additional configs are provided they will be merged
846
846
// on top of the Session's copied config.
847
847
//
848
- // // Create a copy of the current Session, configured for the us-west-2 region.
849
- // sess.Copy(&aws.Config{Region: aws.String("us-west-2")})
848
+ // // Create a copy of the current Session, configured for the us-west-2 region.
849
+ // sess.Copy(&aws.Config{Region: aws.String("us-west-2")})
850
850
func (s * Session ) Copy (cfgs ... * aws.Config ) * Session {
851
851
newSession := & Session {
852
852
Config : s .Config .Copy (cfgs ... ),
0 commit comments