When using saml2aws to assume AWS roles from a single-sign-on account, you'll need to get new credentials every workday (if not hourly). And users who use multiple accounts need to manage multiple sessions. It becomes hard to track which sessions you have active, and which sessions are expired.
This script prints a table of your saml2aws sessions and which are currently valid.
Get Deno if you don't have it already. Deno is very handy for writing and using small isolated scripts such as this.
Here's a multiline command to install this command with Deno, you can copy/paste it as-is if you're using a normal Linux or Mac setup.
deno install \
--allow-read=$HOME/.aws/credentials \
https://gist.githubusercontent.com/danopia/5a63d8bd7fa19ca87d7b9029473b38fd/raw/96bbeacaae352f091f95fb4cae0d9144444bdf13/aws-profiles.ts \
$HOME/.aws/credentials
You'll need to adjust the paths if using in Windows without a Linuxy environment, or if your credentials file is in a nonstandard location.
Once installed, just run aws-profiles
.
You can use the fzf
fuzzy-selector program to select table rows and export the AWS_PROFILE variable.
# sh/bash/zsh:
export AWS_PROFILE="$(aws-profiles|sed '1,3d;$d'|sed '$d'|fzf --header-lines=3 -n 2|cut -d' ' -f2)"
# Fish shell:
set -x AWS_PROFILE (aws-profiles|sed '1,3d;$d'|sed '$d'|fzf --header-lines=3 -n 2|cut -d' ' -f2)
$ aws-profiles
.------------------------------------------------------------------------.
| Local AWS Profiles |
|------------------------------------------------------------------------|
| AWS_PROFILE | Validitiy | AWS Account | Role name |
|--------------------|-------------------|--------------|----------------|
| live-Developer | ❌ Expired | 123145121342 | StaffDeveloper |
| live-ReadOnly | ✅ Until 22:56:48 | 123145121342 | StaffReadOnly |
| staging-Developer | ✅ Until 22:56:43 | 643515213532 | StaffDeveloper |
| staging-ReadOnly | ❌ Expired | 643515213532 | StaffReadOnly |
'------------------------------------------------------------------------'