📝

今から始める Elastic Beanstalk 入門 #5

に公開

今から始める Elastic Beanstalk 入門シリーズの 5 回目です。
各回については以下のリンクからご覧ください。

  1. 今から始める Elastic Beanstalk 入門 #1
  2. 今から始める Elastic Beanstalk 入門 #2
  3. 今から始める Elastic Beanstalk 入門 #3
  4. 今から始める Elastic Beanstalk 入門 #4

前回は EB CLI について紹介しました。
今回は config ファイルについて紹介します。

Config ファイルとは

Advanced environment customization with configuration files (.ebextensions) - AWS Elastic Beanstalk

You can add AWS Elastic Beanstalk configuration files (.ebextensions) to your web application's source code to configure your environment and customize the AWS resources that it contains. Configuration files are YAML- or JSON-formatted documents with a .config file extension that you place in a folder named .ebextensions and deploy in your application source bundle.

  • .ebextensions ディレクトリ配下に作成するファイル
  • Elastic Beanstalk 環境に関連する AWS リソースをカスタマイズできる
  • option_settings で Elastic Beanstalk 環境内のリソースやアプリケーションを実行するソフトウェアを指定できる
  • Resources で CloudFormation の記法でリソースを追加できる

また、Linux と Windows でもそれぞれ固有のセクションが提供されているため、プラットフォームに応じたカスタマイズも可能です。

option_settings の例

Option settings - AWS Elastic Beanstalk
以下の例では Elastic Beanstalk 環境で起動する EC2 インスタンスのもとになる起動設定で、ボリュームタイプを指定しています。

option_settings:
  - namespace: "aws:autoscaling:launchconfiguration"
    option_name: "RootVolumeType"
    value: "gp3"

Resources の例

Elastic Beanstalk 環境の Auto Scaling ヘルスチェック設定 - AWS Elastic Beanstalk
以下の例では Auto Scaling グループのヘルスチェックにロードバランサーを追加しています。

Resources:
  AWSEBAutoScalingGroup:
    Type: "AWS::AutoScaling::AutoScalingGroup"
    Properties:
      HealthCheckType: ELB
      HealthCheckGracePeriod: 300

Resources で Lambda 関数を追加してみる

option_settings については前回のブログで上述のボリュームタイプの指定を行いました。
今から始める Elastic Beanstalk 入門 #4

config ファイル作成

そのため、今回は Resources を試してみましょう。
Resources で Lambda 関数を追加する手順については以下のブログで紹介していますのでお試しください。
Elastic Beanstalk の config ファイルで遊んでみた

上記ブログでは Auto Scaling グループのヘルスチェック設定と Lambda 関数を追加していますが、CloudFormation でサポートされているリソースであれば他の AWS サービスも追加可能です。
Adding and customizing Elastic Beanstalk environment resources - AWS Elastic Beanstalk

All AWS CloudFormation resources types are supported.

まとめ

今回は今から始める Elastic Beanstalk 入門シリーズの 5 回目として、config ファイルについて紹介しました。
次回はワーカー環境について紹介します。

今から始める Elastic Beanstalk 入門 #6 へ続く

参考資料

Discussion