profile名だけ取得する
複数の環境を使っている人向け。
このコマンドでdefault以外のprofile名が取得できる。
$(cat ~/.aws/config | grep \\\[profile | sed -e "s/\[profile //g" -e "s/]//g")
profile名つけないでコマンド叩いちゃったときが怖いので、自分はdefaultのcredentialsは
[default]
aws_access_key_id = xxxxxxxxxx
aws_secret_access_key = xxxxxxxxx
という感じで無効化しているので、defaultはあえて取得していない。
応用
こんな感じにシェルスクリプトを書くとすべての環境に一括でなんやかんやできる。
#!/bin/bash
profiles=($(cat ~/.aws/config | grep \\\[profile | sed -e "s/\[profile //g" -e "s/]//g"))
for profile in ${profiles[@]}; do
export AWS_PROFILE=$profile
#ここにaws-cliコマンドを書く
done