Skip to content

Instantly share code, notes, and snippets.

@jaymecd
Forked from giuliocalzolari/.bash_profile
Last active March 15, 2018 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaymecd/f749e270a8c61391a9fd959b1a275244 to your computer and use it in GitHub Desktop.
Save jaymecd/f749e270a8c61391a9fd959b1a275244 to your computer and use it in GitHub Desktop.
aws cli helper
# Place following snippets into ~/.profile, ~/.bash_profile or other similar file.
# auto-mfa
complete -W "$(ls -1 ~/.aws/*.mfa | awk -F "/" '{print $NF}' | sed -e 's/\.mfa$//')" mfa mfa_token
function mfa_token () {
oathtool --base32 --totp "$(cat ~/.aws/$1.mfa)"
}
function mfa () {
mfa_token "$1" | pbcopy # OSX only
}
# manual mfa
function mmfa () {
oathtool --base32 --totp "$1" ;
}
# AWS profile switch
complete -W "$(cat ~/.aws/config |grep '\[profile' | sed 's/\[profile //' | sed 's/\]//')" paws
function paws() {
export AWS_DEFAULT_PROFILE=$1
}
# AWS region set
complete -W "ap-south-1 eu-west-3 eu-west-2 eu-west-1 ap-northeast-2 ap-northeast-1 sa-east-1 ca-central-1 ap-southeast-1 ap-southeast-2 eu-central-1 us-east-1 us-east-2 us-west-1 us-west-2" region_aws
function region_aws() {
export AWS_DEFAULT_REGION=$1
}
# AWS S3 force remove
function rrm_s3() {
aws s3 rm s3://$1 --recursive
aws s3 rb s3://$1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment