Skip to content

Instantly share code, notes, and snippets.

@josh-padnick josh-padnick/README.md
Last active May 17, 2017

Embed
What would you like to do?
Manually Edit AWS Console "Switch Role" Configuration in Bash

Manually Edit AWS Console "Switch Role" Configuration in Bash

Motivation

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.

Prerequisites

  1. Make sure NodeJS is installed.
  2. Make sure jq is installed.
  3. These intructions assume the Google Chrome web browser.

Environment Setup

In your terminal, add the following bash aliases:

alias urlencode_js='node -e "console.log(encodeURIComponent(process.argv[1]))"'
alias urldecode_js='node -e "console.log(decodeURIComponent(process.argv[1]))"'

Instructions

  1. Using Google Chrome Dev Tools, visit the AWS console, copy the cookie value for the property noflush_awsc-roleInfo.

  2. Run the following in your terminal to get the JSON object:

     urldecode_js "<cookie-value>" | jq
  3. Make edits as desired in a separate text editor to get your updated JSON value.

  4. Re-encode it. We use -c to strip all whitespace.

    urlencode_js $(echo '<new-json-value>' | jq -c)
  5. Use Chrome Dev Tools to write that value back into the noflush_awsc-roleInfo property of the Cookie.

Open Issue

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.

Alternatives

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.