You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
aws sso login should respect credential expiration #6948
Currently, aws sso login goes through the log in process whenever it's called. So if I have two profiles foo and bar that share the same AWS SSO configuration (i.e., sso_start_url and sso_region), when I call aws sso login --profile foo, it will pop up a browser window, log me in, etc., resulting in a valid token being cached in ~/.aws/sso/cache. If I then call aws sso login --profile bar (or aws sso login --profile foo again, for that matter), despite having a valid token for that config, it will go through the entire login process again, resulting in a new token.
Use Case
It's unnecessary work, and it's exacerbated by the argument to aws sso login being --profile, which leads people to think they need to call it whenever they're using a particular profile (I wrote an explainer to help people understand they don't need to do that).
Proposed Solution
aws sso login should check the expiration of the cached token, and exit out successfully if the token is not expired. There should be a --force-refresh option to override this.
Other Information
No response
Acknowledgements
I may be able to implement this feature request
This feature might incur a breaking change
CLI version used
N/A
Environment details (OS name and version, etc.)
N/A
Reacted by Loren Gordon, tris, yokoyama tatsuo, Christopher Wall, at4z, porrige51122, Maxence, Ian Collar, Mark Mindenhall, Demetrio Carrara and 23 more
Reacted by tris, at4z, Thayne McCombs, Richard Hurt, Cody Robbins and Josh Heidenreich
My team and I use aws sso login during development and found having to log in breaks our concentration multiple times a day.
We use this fairly crude workaround script, but it is messy to make available to all of our usages.
I would much rather delete it and use aws sso login directly 😌 !
if aws sts get-caller-identity > /dev/null ;thenecho'🔑 AWS Credentials AOK ✅'elseecho'🔑 AWS Credential NOK ❎. Logging in via SSO...'
aws sso login
fi
Reacted by Loren Gordon, Oliver Searle-Barnes, yokoyama tatsuo, Josh Heidenreich, François Maillet, Vinícius Francisco Xavier and Drew Burlingame
Reacted by Oliver Searle-Barnes and Joseph Solomon
I have dozens of AWS SSO profiles that I use every day. I use aws-sso-creds to get credentials for local use. After the initial login I check for a valid session in the cache and if there's already one there I skip aws sso login and go straight to aws-sso-creds export. This works for me multiple times a day across multiple AWS orgs.
In other words: don't use aws sso login more than once against the same SSO domain. The credentials are already there.
Hey all, revisiting this as we evaluate open feature requests. We are open to a contribution if somebody gets here before we do.
We don't want to change the default behavior of aws sso login for backwards compatibility. Rather than newly asking users to provide --force to match existing behavior, I'd rather gate the new behavior behind a new --skip-if-valid option (open to naming suggestions there).
I prefer to check if the access and refresh token validity, not whether the temporary credentials from GetRoleCredentials are still valid. As pointed out above: aws sso login is operating on the sso-session as opposed to a specific profile/role, and the ~/.aws/cli/cache directory can muddy the waters.
So for --skip-if-valid, I would:
Locate the right token cache file
If the access token's expiresAt is still valid, return success.
If the refresh token can successfully still be exchanged, do so, and return success.
Otherwise proceed with the full, current workflow.
Hey all, revisiting this as we evaluate open feature requests. We are open to a contribution if somebody gets here before we do.
We don't want to change the default behavior of aws sso login for backwards compatibility. Rather than newly asking users to provide --force to match existing behavior, I'd rather gate the new behavior behind a new --skip-if-valid option (open to naming suggestions there).
I prefer to check if the access and refresh token validity, not whether the temporary credentials from GetRoleCredentials are still valid. As pointed out above: aws sso login is operating on the sso-session as opposed to a specific profile/role, and the ~/.aws/cli/cache directory can muddy the waters.
So for --skip-if-valid, I would:
Locate the right token cache file
If the access token's expiresAt is still valid, return success.
If the refresh token can successfully still be exchanged, do so, and return success.
Otherwise proceed with the full, current workflow.
This looks great to me. Most of us are just looking for a way to automatically check the validity of the session rather than any specific role that can be assumed from that session and login again if it is not valid. Doing this in one command just makes our existing scripts/taskfiles etc more simple and reliable.
If the access token's expiresAt is still valid, return success.
If the refresh token can successfully still be exchanged, do so, and return success.
Otherwise proceed with the full, current workflow.
Agreed on this being the right process, but I'd like to push back a little bit on --skip-if-valid, which requires that people learn about it. If we went the --force-refresh route, so executing the above process by default, and if a valid token was found or retrieved the CLI printed:
Identity Center session appears to still be valid and login not needed. To force a fresh login, use --force-refresh.
what are the use cases that we think would break? I would argue the vast majority of users would be happy not to have to go through the login flow and their use cases would not break. The ones where something still wasn't working, they would get instructions for it directly.
Maybe an alternative is to run the check every time anyway, and if a valid token is found, print "You appear to have a valid session. You can use --skip-if-valid to avoid a fresh login when it is not needed." before still proceeding with the current login flow. But I still think it's worth thinking hard if we can make skip-if-valid behavior the default.
Hi, I use aws sso login daily across several profiles sharing one SSO session, so this bites me too. I'd like to work on a fix: in LoginCommand, check the cached token in ~/.aws/sso/cache before starting the browser flow, and if a token for the same start URL is still valid, print that the session is already active and exit without re-authenticating. I'd also add a --force flag to force a fresh login when needed, and update the command description that currently says a new token is retrieved every time. Does that shape sound right — cache-validity check by default with an opt-out --force — or would you prefer the check to live elsewhere?
Activity
lorengordon commentedon May 14, 2022
So much this, yes, please!
gondalez commentedon May 17, 2022
I came here to report/request this also 🙏 💯
My team and I use
aws sso loginduring development and found having to log in breaks our concentration multiple times a day.We use this fairly crude workaround script, but it is messy to make available to all of our usages.
I would much rather delete it and use
aws sso logindirectly 😌 !nmiekley commentedon May 18, 2022
Thanks for working on this! This would also solve #5972, wouldn't it?
benkehoe commentedon May 18, 2022
It looks like it's the same issue
benkehoe commentedon May 18, 2022
I should note that
aws-sso-util logindoes this already. https://github.com/benkehoe/aws-sso-util/blob/master/docs/login.mdixti commentedon Feb 10, 2023
@gondalez that's awesome. I've modified your solution for myself a bit:
TheJosh commentedon Jul 7, 2023
One-liner that's also quiet:
5 remaining items
kjenney commentedon Nov 21, 2023
I have dozens of AWS SSO profiles that I use every day. I use
aws-sso-credsto get credentials for local use. After the initial login I check for a valid session in the cache and if there's already one there I skipaws sso loginand go straight toaws-sso-creds export. This works for me multiple times a day across multiple AWS orgs.In other words: don't use
aws sso loginmore than once against the same SSO domain. The credentials are already there.ashovlin commentedon Apr 23, 2026
Hey all, revisiting this as we evaluate open feature requests. We are open to a contribution if somebody gets here before we do.
We don't want to change the default behavior of
aws sso loginfor backwards compatibility. Rather than newly asking users to provide--forceto match existing behavior, I'd rather gate the new behavior behind a new--skip-if-validoption (open to naming suggestions there).I prefer to check if the access and refresh token validity, not whether the temporary credentials from
GetRoleCredentialsare still valid. As pointed out above:aws sso loginis operating on thesso-sessionas opposed to a specific profile/role, and the~/.aws/cli/cachedirectory can muddy the waters.So for
--skip-if-valid, I would:expiresAtis still valid, return success.gunzy83 commentedon Apr 24, 2026
This looks great to me. Most of us are just looking for a way to automatically check the validity of the session rather than any specific role that can be assumed from that session and login again if it is not valid. Doing this in one command just makes our existing scripts/taskfiles etc more simple and reliable.
jorhett commentedon Apr 24, 2026
A command to just return 0 or 1 for is-valid (without a login) would also be useful. So steps 1-3 without step 4?
benkehoe commentedon Apr 24, 2026
Agreed on this being the right process, but I'd like to push back a little bit on
--skip-if-valid, which requires that people learn about it. If we went the--force-refreshroute, so executing the above process by default, and if a valid token was found or retrieved the CLI printed:what are the use cases that we think would break? I would argue the vast majority of users would be happy not to have to go through the login flow and their use cases would not break. The ones where something still wasn't working, they would get instructions for it directly.
Maybe an alternative is to run the check every time anyway, and if a valid token is found, print "You appear to have a valid session. You can use --skip-if-valid to avoid a fresh login when it is not needed." before still proceeding with the current login flow. But I still think it's worth thinking hard if we can make skip-if-valid behavior the default.
vurumalla92 commentedon Nov 18, 2026
Hi, I use
aws sso logindaily across several profiles sharing one SSO session, so this bites me too. I'd like to work on a fix: inLoginCommand, check the cached token in~/.aws/sso/cachebefore starting the browser flow, and if a token for the same start URL is still valid, print that the session is already active and exit without re-authenticating. I'd also add a--forceflag to force a fresh login when needed, and update the command description that currently says a new token is retrieved every time. Does that shape sound right — cache-validity check by default with an opt-out--force— or would you prefer the check to live elsewhere?