@@ -84,17 +84,24 @@ export const getDefaultRoleAssumer = (
84
84
logger : logger as any ,
85
85
} ) ;
86
86
}
87
- const { Credentials } = await stsClient . send ( new AssumeRoleCommand ( params ) ) ;
87
+ const { Credentials, AssumedRoleUser } = await stsClient . send ( new AssumeRoleCommand ( params ) ) ;
88
88
if ( ! Credentials || ! Credentials . AccessKeyId || ! Credentials . SecretAccessKey ) {
89
89
throw new Error ( `Invalid response from STS.assumeRole call with role ${ params . RoleArn } ` ) ;
90
90
}
91
+ let accountId ;
92
+ try {
93
+ accountId = AssumedRoleUser . Arn . split ( ":" ) [ 4 ] ;
94
+ } catch ( error ) {
95
+ accountId = undefined ;
96
+ }
91
97
return {
92
98
accessKeyId : Credentials . AccessKeyId ,
93
99
secretAccessKey : Credentials . SecretAccessKey ,
94
100
sessionToken : Credentials . SessionToken ,
95
101
expiration : Credentials . Expiration ,
96
102
// TODO(credentialScope): access normally when shape is updated.
97
103
credentialScope : ( Credentials as any ) . CredentialScope ,
104
+ accountId,
98
105
} ;
99
106
} ;
100
107
} ;
@@ -134,17 +141,24 @@ export const getDefaultRoleAssumerWithWebIdentity = (
134
141
logger : logger as any ,
135
142
} ) ;
136
143
}
137
- const { Credentials } = await stsClient . send ( new AssumeRoleWithWebIdentityCommand ( params ) ) ;
144
+ const { Credentials, AssumedRoleUser } = await stsClient . send ( new AssumeRoleWithWebIdentityCommand ( params ) ) ;
138
145
if ( ! Credentials || ! Credentials . AccessKeyId || ! Credentials . SecretAccessKey ) {
139
146
throw new Error ( `Invalid response from STS.assumeRoleWithWebIdentity call with role ${ params . RoleArn } ` ) ;
140
147
}
148
+ let accountId ;
149
+ try {
150
+ accountId = AssumedRoleUser . Arn . split ( ":" ) [ 4 ] ;
151
+ } catch ( error ) {
152
+ accountId = undefined ;
153
+ }
141
154
return {
142
155
accessKeyId : Credentials . AccessKeyId ,
143
156
secretAccessKey : Credentials . SecretAccessKey ,
144
157
sessionToken : Credentials . SessionToken ,
145
158
expiration : Credentials . Expiration ,
146
159
// TODO(credentialScope): access normally when shape is updated.
147
160
credentialScope : ( Credentials as any ) . CredentialScope ,
161
+ accountId,
148
162
} ;
149
163
} ;
150
164
} ;
0 commit comments