Blog

Easily Switch AWS Profiles with Tab Completion

02.05.2020 | Tutorial Devops | Austin

hero

I am constantly moving between AWS profiles and wrote a bash function to help me hop between what I need.

Hopefully, someone else finds it useful

#!/bin/bash 

_getprofiles() {
    COMPREPLY=($(compgen -W "$(sed -n 's#^\[\(.*\)\]#\1#p' ~/.aws/credentials | sort -u)" -- "${COMP_WORDS[1]}"))
}


aps () {
    if [ -z "$1" ]; then
        echo $AWS_DEFAULT_PROFILE
        return
    fi
    
    export AWS_DEFAULT_PROFILE=$1
}

complete -F _getprofiles aps

Just put that function into your ~/.bash_profile or something that is sourced when a terminal session starts.

This will add the command aps and you can tab complete any of the existing profiles in your aws config.

Share

Read More

Related Posts

related_image

06.30.2021 | Culture | Katy Scott

At Focused Labs, collaboration is key to how we work together; it helps our teams learn from each other, brings us closer and helps us become more efficient...

related_image

06.23.2021 | Culture | Austyn

Late-night feedings and diaper changes, the 3-4 month sleep regression, teething, and a growth spurt all mean I'm getting less sleep than...

related_image

05.12.2021 | Culture Backend Frontend | Ryan Taylor

Temporarily disrupts "normal" business operations and allow self-organized teams to rapid prototype around their interest areas

related_image

04.27.2021 | Culture | Erin Hochstatter

Several years ago, I'd been trying to find an approach to software consulting that made sense for me [...]

related_image

01.28.2021 | Backend | Parker Drake

Recently I found myself needing to validate fields in a Spring Boot controller written in Kotlin...

related_image

01.22.2021 | Tutorial | Luke Mueller

⌘+⇧+g is the way to go

related_image

01.21.2021 | Devops | Katy G

Kube jobs running wild? To delete successful jobs...

additional accent
accent
FocusedLabs

171 N Aberdeen St
Suite 400
Chicago, IL 60607

[email protected]

© 2021 FocusedLabs, All Rights Reserved.

  • facebook icon
  • twitter icon
  • linkedin icon
  • github icon