Help us understand the problem. What is going on with this article?

aws-vault の登録内容から AWS CLI 設定ファイルを作成する

AWS CLI v2とaws-vaultとpecoを使ってプロファイルを選択方式にする で書いた、aws-vault の登録内容から AWS CLI 設定ファイル (~/.aws/config) を作成する shell を作ってみました。

aws_config_maker.sh
#!/bin/sh

# Variables
readonly TARGET_HOME=$HOME/.aws
readonly TARGET_FILE=$TARGET_HOME/config
readonly REGION=ap-northeast-1
readonly OUTPUT=json

# Initialize .aws/config
if [ ! -e "$TARGET_HOME" ]; then
  echo Create a config form folder.
  mkdir -p "$TARGET_HOME"
fi

# Back up .aws/config
if [ -e "$TARGET_FILE" ]; then
  echo Back up config.
  cp -p "$TARGET_FILE" "$TARGET_FILE".`date "+%Y%m%d%H%M%S"`
fi

# Create default profile
echo Register default settings.
cat <<EOF > "$TARGET_FILE"
[default]
credential_process=/usr/local/bin/credential-selector.sh
region=$REGION
output=$OUTPUT
EOF

# Added settings for each credential
for credential in ` aws-vault ls | awk 'NR>2 {if ($2 != "-") print $2}'`
do
  echo Register profile [$credential].
  cat <<EOF >> "$TARGET_FILE"

[profile $credential]
credential_process=aws-vault exec -j $credential --no-session
region=$REGION
output=$OUTPUT
EOF

done

これを実行すると

$ sh ./aws_config_maker.sh
Back up config.
Register default settings.
Register profile [prof1].
Register profile [prof2].
Register profile [prof3].
~/.aws/config
[default]
credential_process=/PATH/TO/credential-selector.sh
region=ap-northeast-1
output=json

[profile prof1]
credential_process=aws-vault exec -j prof1 --no-session
region=ap-northeast-1
output=json

[profile prof2]
credential_process=aws-vault exec -j prof2 --no-session
region=ap-northeast-1
output=json

[profile prof3]
credential_process=aws-vault exec -j prof3 --no-session
region=ap-northeast-1
output=json

って感じで既にファイルがあればバックアップして aws-vault の登録内容から config を生成します。
~/.aws/credentials の方はなんにもしません。

作ってみたものの、かなりの数のクレデンシャルを登録しないと shell の効果を感じることは無さそうな。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした