LoginSignup
229
216

More than 5 years have passed since last update.

ElasticBeanstalk .ebextensions 逆引き辞典

Last updated at Posted at 2015-04-21

ElasticBeanstalkの設定やカスタマイズをする .ebextensions 以下のファイルですが、
これをやるにはどうすんの?というのをいちいち調べないとできないので、調べてやってみた結果を逆引き形式でまとめます。複数のやり方があるので、これがイケてるかどうかは分かりません。

思いつき次第追記していきます。

01. yumでパッケージをインストールする

書くファイル: .ebextensions/01.xxx.config

packages:
  yum:
    git: []

02. timezone を変更する

書くファイル: .ebextensions/01.xxx.config

commands:
  01-set_timezone:
    command: cp /usr/share/zoneinfo/Japan /etc/localtime

03. td-agentをインストールする

04. newrelic のagentをインストールする

Amazon Web Services (AWS) users | New Relic Documentation

書くファイル: .ebextensions/01.newrelic-install.config

packages:
  yum:
    newrelic-php5: []
  rpm:
    newrelic: http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm
commands:
  configure_new_relic:
    command: newrelic-install install
    env:
      NR_INSTALL_SILENT: true
      NR_INSTALL_KEY: [INSERT LICENSE KEY]

05. mackerelのagentをインストールする

06. ドキュメントルートを指定する

書くファイル: .ebextensions/01.xxx.config

option_settings:
  - namespace: aws:elasticbeanstalk:container:php:phpini
    option_name: document_root
    value: /public

07. root volume のサイズを変更する

デフォルトだと 8GBですが、少なすぎる場合は大きくする。

書くファイル: .ebextensions/01-change-root-volume-size.config

option_settings:
  - namespace: aws:autoscaling:launchconfiguration
    option_name: RootVolumeSize
    value: "20"
  - namespace: aws:autoscaling:launchconfiguration
    option_name: RootVolumeType
    value: gp2

※ 2015/06/19 書き方が古いとのことで修正しました。

08. php.ini を設定する

option_settings で指定する場合

いくつかの設定項目は、option_settings で指定できる。
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options.html#command-options-php

指定できる項目は下記

  • document_root
  • memory_limit
  • zlib.output_compression
  • allow_url_fopen
  • display_errors
  • max_execution_time
  • composer_options

(記述例)

option_settings:
  - namespace: aws:elasticbeanstalk:container:php:phpini
    option_name:<オプション名>
    value: <値>

独自の php.ini を設置する場合

上記の option_settingsにない項目を設定したい場合は、独自のiniファイルを作って、php.ini置き場に置けばよい。

(あとで書く)

09. cronを設定する

書くファイル: .ebextensions/99.install-crontab.config

    "/opt/elasticbeanstalk/hooks/appdeploy/enact/99-install-crontab.sh" :
        mode: "000777"
        owner: ec2-user
        group: ec2-user
        content: |
            #!/usr/bin/env bash

            cp -f /var/app/ondeck/crontab/ec2-user /etc/cron.d/ec2-user
            chmod 644 /etc/cron.d/ec2-user

これは、<プロジェクトディレクトリ>/crontab/ec2-user というファイルに cronの内容を書いておいて、それを /etc/cron.d/ にコピーする方法です。

crontab/ec2-user のファイルの中身は普通の crontabの記述とは違って下記のような感じです。

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=ec2-user
HOME=/

*/30 * * * * ec2-user <実行するコマンド>

10. ec2インスタンスにタグ付けする

(あとで書く)

11. instance profile を指定する

$ eb create <環境名> \
    --instance_profile   <IAMロール> \

12. vpc 内に起動する

Environment生成時に指定する方法

$ eb create <環境名> \
    --vpc.id             vpc-xxxxxxxx \
    --vpc.ec2subnets     subnet-xxxxxxxx \

13. vcpのセキュリティグループを指定する

Environment生成時に指定する方法

$ eb create <環境名> \
    --vpc.id             vpc-xxxxxxxx \
    --vpc.ec2subnets     subnet-xxxxxxxx \
    --vpc.securitygroups sg-xxxxxxxx \

14. インスタンスの鍵を指定する

Environment生成時に指定する方法

$ eb create <環境名> \
    --keyname  <キー名> \

option_settings で指定する方法

option_settings:
  - namespace:   aws:autoscaling:launchconfiguration
    option_name: EC2KeyName
    value:       MyKeyName

15. cname を指定する

Environment生成時に指定する方法

$ eb create <環境名> \
    --cname     <CNAME> \

CNAMEは、 xxxx.elasticbeanstalk.com の xxxx の部分になる。

16. deploy時に composer update する (PHP)

(あとで書く)

17. カスタムAMIを使う

1)ベースとするBeanstalk のAMIを元にInstanceを立てる(Platform毎にいろいろあるので選択)
2)Instanceをカスタマイズ
3)Instanceを元にAMIを作成
4)Beanstalk の使うAMI を3)に設定

本家ドキュメント
http://docs.aws.amazon.com/ja_jp/elasticbeanstalk/latest/dg/using-features.customenv.html

18. ヘルスチェックのURLを設定する

option_settings で指定

option_settings:
  - namespace:   aws:elasticbeanstalk:application
    option_name: "Application Healthcheck URL"
    value: /check.php

19. SNSの通知を設定する

option_settings で指定

option_settings:
  - namespace:   aws:elasticbeanstalk:sns:topics
    option_name: "Notification Endpoint"
    value:       hoge@example.com

20. ELBのHTTPSを設定する(証明書を指定)

option_settings で指定

option_settings:
  - namespace: aws:elb:loadbalancer
    option_name: LoadBalancerHTTPSPort
    value: 443
  - namespace: aws:elb:loadbalancer
    option_name: SSLCertificateId
    value: "arn:aws:iam::xxxxxx:server-certificate/cloudfront/xxxxx/xxxxxxxx"
  - namespace: aws:elb:loadbalancer
    option_name: LoadBalancerSSLPortProtocol
    value: HTTPS

21. インスタンスタイプを指定する

Environment生成時に指定する方法

$ eb create <環境名> \
    --instance_type      c3.large 

option_settings で指定

option_settings:
  - namespace:   aws:autoscaling:launchconfiguration
    option_name: InstanceType
    value:       t2.micro

22. AutoScaleのトリガー設定

option_settings で指定

下記は、2分間のCPU使用率が40%だったら1台増やす、20%だったら1台減らす設定。

option_settings:
  - namespace: aws:autoscaling:trigger
    option_name: MeasureName
    value: CPUUtilization
  - namespace: aws:autoscaling:trigger
    option_name: Statistic
    value: Average
  - namespace: aws:autoscaling:trigger
    option_name: Unit
    value: Percent
  - namespace: aws:autoscaling:trigger
    option_name: UpperThreshold
    value: "40"
  - namespace: aws:autoscaling:trigger
    option_name: LowerThreshold
    value: "20"
  - namespace: aws:autoscaling:trigger
    option_name: UpperBreachScaleIncrement
    value: "1"
  - namespace: aws:autoscaling:trigger
    option_name: LowerBreachScaleIncrement
    value: "-1"
  - namespace: aws:autoscaling:trigger
    option_name: BreachDuration
    value: "2"

23. ファイルをダウンロードして展開する

.ebextensions/xxx.config

sources:
  /var/app/current/public/: https://s3-ap-northeast-1.amazonaws.com/xxxxxxx/xxxxxxx.tgz

※ /var/app/current/public/ に xxxxxxx.tgz の中身がぶちまけられる。


参考ページ

229
216
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
229
216