Skip to content

Is there any API or automated method to retrieve my current short-term credentials?

0

Our company is having us use short-term credentials. They're stored locally in the default location %USERPROFILE%.aws\credentials.

We retrieve the credentials as described in the AWS documentation here.

But, as the documentation says, "Repeat these steps each time your credentials expire". Which for us is twice a day. This is tedious, and annoying, especially when the credentials expire before we notice.

Are the credentials available at any direct URL? Or is there an API or other automated means for us to retrieve our current short-term credentials, in the same text format as we'd get by clicking the button for "Copy Profile information for AWS credentials file", as shown below? So we might automate this somehow?

I could try something like scraping the information from that "Get credentials for ..." popup, but it has no direct URL that I could find. Plus, if the page format changes, I'd need to fix my scraper.

screenshot

2 Answers
6
Accepted Answer

How about leveraging the AWS STS API (AWS Security Token Service API) to programmatically request temporary credentials. The AssumeRole or GetSessionToken API calls can provide short-term credentials that you can store in your credentials file.

https://docs.aws.amazon.com/STS/latest/APIReference/welcome.html

EXPERT

answered a year ago

AWS
SUPPORT ENGINEER

reviewed a year ago

  • Perfect..!! That's exactly what I was looking for. Thank you.

0

Hey,

Hope you're keeping well.

If your organization issues short-term credentials via AWS SSO or STS, you can automate renewal using the AWS CLI or SDKs rather than manually copying from the console. For AWS SSO, run aws sso login and then use aws sso get-role-credentials to fetch and write credentials to your ~/.aws/credentials file. For STS-based flows, call sts:GetSessionToken or sts:AssumeRole with the appropriate IAM permissions, then update your local profile from the API response. Wrapping this in a script or scheduled task can refresh credentials before expiry without relying on manual console steps.

Thanks and regards,
Taz

answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.