27
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Elastic Beanstalkでアプリ内から好き勝手なことを出来るようにする

Posted at

.ebextensionsによる初期化処理

Elastic Beanstalkでは、アプリケーションディレクトリの直下の.ebextensionsディレクトリに.configで終わるファイルを用意しておくと、アプリケーションをpushした際に良きに計らっていろんなことをしてくれる。

configファイルはYAMLで記述する。詳細はこちらを参照すると良い。

なお、処理の順番は、以下の通りで、packages〜servicesまでは、Webサーバの準備が終わっていて、まだアプリが抽出されていない時点で実施され、container_commandsは、Webサーバの準備が終わり、かつアプリの抽出が終わっていてデプロイされる前に実行される

  • packages
  • files
  • commands
  • services
  • container_commands

sudoできるようにする

ということでアプリからコマンドをキックしたりしたい場合にsudoの設定を変えたい場合はよくある。Elastic BeanstalkではカスタムAMIが利用できるので、予め自分でAMIを作っておいてもよいが、初期化処理の中でやってしまうのが保守性を含めて簡単である。

以下がその例。まずsudoするときにttyを必要としてしまうとアプリ内からキックできないのでこいつを無効にする。その上で、Elastic Beanstalkのアプリ用ユーザーのwebappに対してパスワードなしでsudoできるように設定している

commands:
  01_sudo:
    command: "sed -i 's/^.*requiretty/#Defaults requiretty/' /etc/sudoers"
  02_sudo_webapp:
    command: "grep -q 'webapp ALL=(ALL) NOPASSWD: ALL' /etc/sudoers || echo -e 'webapp ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers"

これで色々自由になるはず。

もっと自由にしたかったら?

ドキュメントに書いていないが、hookを使うと、適用のタイミングを含めてもっと自由に使える。

27
24
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
27
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?