理系学生日記

おまえはいつまで学生気分なのか

CodePipeline 失敗時のトラブルシュートのノウハウ

CodePipeline + CodeDeploy で ECS へのデプロイメントパイプラインを組んでいたんですが、このパイプラインが様々な理由で失敗します。

マネジメントコンソールで確認しても、Internal error 的な文言しか表示されず、とにかくデバッグがしんどいです。 つらい。本当につらい。

どうしたものかと思っておりましたが、現状で理解しているおおよそのデバッグ方針は以下になります。

codepipeline list-action-executions

多分パイプラインの一番粒度の細かい情報が得られるのは codepipeline list-action-executions。 各ステージ、アクションの詳細情報やエラーが確認できます。

ListActionExecutions , which returns action-level details for past executions. The details include full stage and action-level details, including individual action duration, status, any errors that occurred during the execution, and input and output artifact location details.

https://docs.aws.amazon.com/cli/latest/reference/codepipeline/index.html

僕は大体 actionExecutionDetails[].output 周りを確認しています。

$ aws codepipeline list-action-executions --pipeline-name パイプライン名 | jq '.actionExecutionDetails[0].output'
{
  "outputArtifacts": [],
  "executionResult": {
    "externalExecutionSummary": "The provided role does not have permissions to perform this action."
  },
  "outputVariables": {}
}

ECS

Deploy ステージまで到達したら、そのあとは ECS のマネジメントコンソールだったり task の状態を確認します。 CodeDeploy まで到達した後のトラブルは、CodePipeline 云々ではなく ECS で発生していることが多い。

この間 CodeDeploy が 1 時間近く終わらなくてなんでだと思っていたら、ECR のバケットポリシーがおかしくて ECS から Image を Pull できなかった、ということがあった。

$ aws ecs list-tasks --cluster [クラスタ名] | jq -r '.taskArns[]' | xargs -I% aws ecs describe-tasks --cluster [クラスタ名] --tasks %