Manually Edit AWS Console "Switch Role" Configuration in Bash
At Gruntwork, we work with multiple software teams. That means we have to modify the "Switch Role" history multiple times. But the only way to do that today is to delete your cookie and clear all AWS Console saved settings. That got old after a while, so these instructions enable you to modify the "Switch Roles" configuration directly.
The Big Picture
AWS stores "Switch Role" values in the
noflush_awsc-roleInfo property of the cookie associated with the AWS Console. That values we need
to modify are JSON objects that are URI encoded. Our approach will be to simply get the value from the cookie, decode it, edit it, re-encode
it, and put it back into the cookie.
- Make sure NodeJS is installed.
- Make sure jq is installed.
- These intructions assume the Google Chrome web browser.
In your terminal, add the following bash aliases:
alias urlencode_js='node -e "console.log(encodeURIComponent(process.argv))"' alias urldecode_js='node -e "console.log(decodeURIComponent(process.argv))"'
Using Google Chrome Dev Tools, visit the AWS console, copy the cookie value for the property
Run the following in your terminal to get the JSON object:
urldecode_js "<cookie-value>" | jq
Make edits as desired in a separate text editor to get your updated JSON value.
Re-encode it. We use
-cto strip all whitespace.
urlencode_js $(echo '<new-json-value>' | jq -c)
Use Chrome Dev Tools to write that value back into the
noflush_awsc-roleInfoproperty of the Cookie.
For some reason, pasting this value into the cookie doesn't work, and I have to move on from this 10-minute side project, but I'm guessing I'm one tweak away from having these instructions correct.
There's also an AWS Role Editor, though I'm personally paranoid about all Chrome extensions so I feel more comfortable doing these manual steps on my own.