LoginSignup
1
1

More than 3 years have passed since last update.

awscliのprofile名をすべて取得する方法

Posted at

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
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1