1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

チーム開発の環境変数共有をAWS Secrets Managerで効率化

Posted at

はじめに

開発チームで .env ファイルを共有する際これまでは

  • SlackのDMやメールで .env ファイルを送ってました
    まぁそんなに困らないんですが、開発メンバーが新たに入ってきた時などに地味にめんどくさいのでAWS Secrets Manager で管理することにしました。

仕組み

Secrets ManagerにJSON形式で環境変数を保存し、CLIで取得して .env 形式に変換します。

手順

1. 前提条件

以下がインストールされている必要があります。

# macOS
brew install awscli jq

2. AWS認証情報を設定

AWS Portalから一時認証情報を取得し、ターミナルに貼り付けて実行します。
SSOが使える環境の方なら aws sso login の方がいいかも

export AWS_ACCESS_KEY_ID=xxxxx
export AWS_SECRET_ACCESS_KEY=xxxxx
export AWS_SESSION_TOKEN=xxxxx

3. ワンコマンドで .env を生成

aws secretsmanager get-secret-value \
  --secret-id arn:aws:secretsmanager:ap-northeast-1:123456789012:secret:local-env-xxxxx \
  --query SecretString \
  --output text | jq -r 'to_entries[] | "\(.key)=\(.value)"' >| .env

これだけで最新の環境変数が手元に揃います。

コマンド解説

部分 説明
aws secretsmanager get-secret-value Secrets Managerからシークレット取得
--query SecretString --output text JSON文字列だけを取り出す
jq -r 'to_entries[] | "\(.key)=\(.value)"' KEY=VALUE 形式に変換

まとめ

新メンバーの参加時に「AWSにログインしてこのコマンド叩いて」で済むようになりました。
地味に便利です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?