0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Elastic Beanstalkの環境変数をデプロイ時に自動追加

Posted at

Elastic Beanstalkで開発環境を作成するときに、毎回環境変数を手入力するのが面倒でした。
Elastic Beanstaklの環境変数でAWS Secrets Manager および AWS Systems Manager パラメータストアに対応したようなので、以下の公式ドキュメントを参考に実装してみました。

なお2025年3月28日以降のプラットフォームバージョンしか対応していないようなので、以下の公式サイトを見て対応しているか確認する必要があります。

私は「PHP 8.3 AL2023 version 4.6.0」のプラットフォームバージョンで実装しました。

ebextensions/options.configの作成

option_settings:
  - namespace: aws:elasticbeanstalk:application:environmentsecrets
    option_name: APP_KEY
    value: arn:aws:ssm:ap-northeast-1:〜〜〜〜〜〜〜〜

上記の形で追加したい環境変数を記載する。

Elastic BeanstalkのIAMロールに権限追加

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "secretsmanager:GetSecretValue",
            "Resource": "secretmanagerのARNを記載"
        }
    ]
}

上記の権限を追加しないと、パラメータストアから値を取得できないため、必ず追加してください。

デプロイすると、環境変数が追加されます。

自分の場合はcodepipelineでCI/CDを構築しているため、deploy時に環境変数が以下のように追加されました!

unnamed.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?