Skip to content

Instantly share code, notes, and snippets.

@buckett
Created January 16, 2025 15:24
Show Gist options
  • Select an option

  • Save buckett/030e1ce69036533e219c58ead5156126 to your computer and use it in GitHub Desktop.

Select an option

Save buckett/030e1ce69036533e219c58ead5156126 to your computer and use it in GitHub Desktop.
AWS CLI Chrome Profiles

Launching Chrome profiles for AWS CLI

Introduction

When an AWS account is set up to use AWS IAM Identity Center it's common to have SSO integration. The CLI then uses temporary credentials to access the AWS account that need to be refreshed on a regular basis. This is normally done with the command aws sso login which launches the default browser for the user to authorize the CLI to access the account. If you want to use a non-standard Chrome profile for AWS this is how.

Shell Script

You need a shell script to launch Chrome with the correct profile. Here is an example script that you can use:

#!/bin/bash

# This script is needed because you don't seem to be able to use the command with arguments with the `BROWSER` environmental
# variable. So this script adds the arguments.

# Set this to the name of the profile directory you want to use.
# The profile directory is located in `~/Library/Application Support/Google/Chrome/`
profile="Profile XXXX"

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --profile-directory="${profile}" $*

I put this script a file called aws-login.sh in my ~/bin directory and made it executable with chmod +x ~/bin/aws-login.sh.

Bash Alias

To get the aws command to use this script when it needs to launch a web browser set the BROWSER environmental variable. I did this by adding an alias to the end of my .bashrc file:

alias aws='BROWSER=~/bin/aws-login.sh aws'

Usage

Just run aws sso login and the script will launch Chrome with the correct profile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment