LoginSignup
6
2

More than 5 years have passed since last update.

CodedeployのLifeCycleに関するメモ

Last updated at Posted at 2017-05-19

CodedeployのLifeCycleに関する雑な理解

大きくアプリケーション周りのライフサイクル(7つ)とロードバランサーに関係するライフサイクル(6つ)がある。初回デプロイ時にはDownloadBundleされる前のApplicationStopはrunscriptがないので実行されない。

Application周りのライフサイクル(Application止めて、正常稼働確認まで)

  • ApplicationStop
  • DownloadBundle
  • BeforeInstall
  • Install
  • AfterInstall
  • ApplicationStart
  • ValidateService

LB周りのライフサイクル

  • BeforeBlockTraffic
  • BlockTraffic
  • AfterBlockTraffic
  • BeforeAllowTraffic
  • AllowTraffic
  • AfterAllowTraffic

runscriptの実行可否一覧

IP:InPlaceDeployment
BG:Blue/GreenDeployment
BGR:Blue/GreenDeployment Rollback
CLB:ClassicELB

◯:runscriptは実行される
△:runscriptは場合によって実行される(2回目以降のデプロイから)
×:runscriptは実行されない
太字:runscriptは実行されない。codedeploy占有。

LifeCycleEvent IP(LB無し) IP+CLB IP+ALB BG(Blue) BG(Green) BGR(Blue) BGR(Green)
1.ApplicationStop × × ×
2.DownloadBundle × × × × × × ×
3.BeforeInstall × × ×
4.Install × × × × × × ×
5.AfterInstall × × ×
6.ApplicationStart × × ×
7.ValidateService × × ×
8.BeforeBlockTraffic × × × ×
9.BlockTraffic × × × × × × ×
10.AfterBlockTraffic × × × ×
11.BeforeAllowTraffic × × × ×
12.AllowTraffic × × × × × × ×
13.AfterAllowTraffic × × × ×

runscript内で使える環境変数

個人的にDEPLOYMENT_GROUP_NAMEくらいしか使わない。

  • APPLICATION_NAME
  • DEPLOYMENT_ID
  • DEPLOYMENT_GROUP_NAME
  • DEPLOYMENT_GROUP_ID
  • LIFECYCLE_EVENT

個人的Tips

  • runscriptの名前にイベントの順序ごとに番号つける。1_application_stop.sh等にしておくと順序悩まない。
  • とりあえずEC2のUSERDATAやAutoScalingのLaunchConfigurationに以下のコード入れて置くと楽。
#!/bin/bash
REGION=$(curl 169.254.169.254/latest/meta-data/placement/availability-zone/ | sed 's/[a-z]$//')
yum install -y aws-cli
cd /home/ec2-user/
aws s3 cp s3://aws-codedeploy-${REGION}/latest/install . --region ${REGION}
chmod +x ./install
./install auto

参考

Lifecycle Event Hook Availability

6
2
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
6
2