kakakakakku blog

Weekly Tech Blog: Keep on Learning!

CodeDeploy エージェントのログに Missing credentials と出たら codedeploy-agent を再起動する

最近 CodeDeploy の検証をしていて,codedeploy-agent のエラーログに少しハマったので,メモ程度に残しておく.

aws.amazon.com

Amazon Linux に codedeploy-agent をインストールする

公式ドキュメントに書いてある手順で,問題なくインストールできた.

$ wget https://aws-codedeploy-ap-northeast-1.s3.amazonaws.com/latest/install
$ chmod +x ./install
$ sudo ./install auto
$ sudo service codedeploy-agent status
The AWS CodeDeploy agent is running as PID 29095

IAM Role を割り当てる

CodeDeploy を使う場合,2種類の IAM Role を作る必要がある.今回は公式ドキュメントの通りに設定をした.

  • CodeDeploy に割り当てる IAM Role
  • EC2 に割り当てる IAM Role

docs.aws.amazon.com

docs.aws.amazon.com

エラーログ : Missing credentials

次に codedeploy-agent のログファイル /var/log/aws/codedeploy-agent/codedeploy-agent.log を見ると,以下のようなエラーログがずっと出ていた.

2018-06-25 22:44:53 INFO  [codedeploy-agent(8311)]: Version file found in /opt/codedeploy-agent/.version with agent version OFFICIAL_1.0-1.1518_rpm.
2018-06-25 22:44:53 ERROR [codedeploy-agent(8311)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Missing credentials - please check if this instance was started with an IAM instance profile
2018-06-25 22:46:23 INFO  [codedeploy-agent(8311)]: Version file found in /opt/codedeploy-agent/.version with agent version OFFICIAL_1.0-1.1518_rpm.
2018-06-25 22:46:23 ERROR [codedeploy-agent(8311)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Missing credentials - please check if this instance was started with an IAM instance profile

Missing credentials - please check if this instance was started with an IAM instance profile と出ているので,EC2 に割り当てた IAM Role 関連だなーと思ったけど,何度見直してもうまく割り当たっていて,最終的に codedeploy-agent を再起動したら解決した.ウッ!

$ sudo service codedeploy-agent restart
Restarting codedeploy-agent:

まとめ

今回インスタンスを起動してから IAM Role を割り当てたので,順番が良くなくて,無駄にハマってしまった.「IAM Role を後から割り当てる場合は codedeploy-agent を再起動する」と覚えておくと良さそう.引き続き CodeDeploy を検証するぞ!