Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@Ricordanza

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

More than 1 year has passed since last update.

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=/PATH/TO/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 の効果を感じることは無さそうな。

0
Help us understand the problem. What is going on with this article?
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
Ricordanza
AWSにはまり縁あってクラウドの世界へ。 最近物忘れが激しくなってきたのでQiitaにアレコレ残す事にしました。
cloudpack
Amazon Web Services (AWS) の導入設計、環境構築、運用・保守をサポートするマネジドホスティングサービス

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?