Allow for IAM credentials with longer duration than 1 hour (re: storage upload)
See original GitHub issueIs your feature request related to a problem? Please describe. I have large files that need to be uploaded and the Storage functionality is very useful, but always gets back credentials that expire in the default time of 1 hour, and the uploads tend to take longer.
Describe the solution you’d like Because IAM roles allow for longer duration (up to 12 hours), and because the Storage.put operation is not retryable (the underlying .upload multipart function), it does not seem possible to catch expiration, update credentials and try again. It seems that the only solution is to get longer-lasting credentials in the first place. From what I’ve read, it looks like the longer-lasting credentials (a) need to be set up in the IAM role (a quick edit) and (b) require a longer duration parameter (DurationSeconds) when requested. The introduction of a DurationSeconds-like parameter for getting storage upload credential would be quite helpful.
Describe alternatives you’ve considered Initially, I tried to catch the error, update the authentication and retry, but when that didn’t work, I did some further research and came to the conclusions above. I have tried to get my own credentials using code similar to the AWS Amplify code as a start, but for some reason the credentials I get back are always expired, so I’m stuck and can’t move forward with an outside-of-aws-amplify solution:
private _setCredentialsFromSession(session): Promise<ICredentials> {
logger.debug('set credentials from session');
const idToken = session.getIdToken().getJwtToken();
const { region, userPoolId, identityPoolId } = this._config;
if (!identityPoolId) {
logger.debug('No Cognito Federated Identity pool provided');
return Promise.reject('No Cognito Federated Identity pool provided');
}
const key = 'cognito-idp.' + region + '.amazonaws.com/' + userPoolId;
const logins = {};
logins[key] = idToken;
const credentials = new AWS.CognitoIdentityCredentials(
{
IdentityPoolId: identityPoolId,
Logins: logins
}, {
region
});
Additional context Thanks for the terrific library and the effort put into it thus far.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:14

Top Related StackOverflow Question
I needed a workaround, so I came up with the following. It’s a bit ugly, I’m sure, but so far it’s worked for me. The idea is to ultimately use a method that gives temporary credentials but allows for “DurationSeconds” to be used. Following the explanation in the CognitoIdentityCredentials API, this approach uses STS’ assumeRoleWithWebIdentity after getting Cognito’s getOpenIdToken.
any updates? 😃