CodeDeployで遭遇したエラー

CodeDeployを初めて触ってみたのですが、すごい単純なミスをしてしまったので備忘録です。
ググってもCodeDeploy AgentのGitHubソースコードしか出てこなかったので、もし同じようなミスをするような人が現れた時のために書いておきます。

遭遇したエラー

appspec.ymlの記述ミス

実行に失敗した時のappspec.ymlとエラー内容が以下です。

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ec2-user
hooks:
  ApplicationStart:
    - location: scripts/start.sh
    - runas: root
2021-12-01 08:26:07 ERROR [codedeploy-agent(3807)]: InstanceAgent::Plugins::CodeDeployPlugin::Comm
andPoller: Error during perform: InstanceAgent::Plugins::CodeDeployPlugin::ApplicationSpecificatio
n::AppSpecValidationException - The deployment failed because the application specification file s
pecifies a script with no location value. Specify the location in the hooks section of the AppSpec
 file, and then try again. - /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/applicati
on_specification/application_specification.rb:90:in `block (2 levels) in parse_hooks'

location の値がないと言われています。ちゃんと書いているのになんでかなと思っていたのですが、正しい書き方は以下です。

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ec2-user
hooks:
  ApplicationStart:
    - location: scripts/start.sh
      runas: root

yamlの書き方を間違ってますね...
配列とハッシュを間違えるのはたまにやってしまうので気をつけたい所存です。

docs.aws.amazon.com

buildspec.ymlの記述ミス(CodeBuildのartifactsにないファイルを実行しようとしている)

エラー文が以下です。

2021-12-01 08:50:51 ERROR [codedeploy-agent(3807)]: InstanceAgent::Plugins::CodeDeployPlugin::Comm
andPoller: Error during perform: InstanceAgent::Plugins::CodeDeployPlugin::ScriptError - Script do
es not exist at specified location: /opt/codedeploy-agent/deployment-root/b62cd4a6-19fc-4524-bbc3-
88e8d2697ad9/d-4VL3MO17E/deployment-archive/scripts/start.sh

CodePipelineでCodeBuild→CodeDeployとしていたのですが、CodeBuildのbuildspec.ymlで 上記appspec.yml中に指定している scripts/ 以下をartifactsに指定し損ねていました。

まとめ

公式ドキュメントの例をちゃんと見て、小さいミスに気を付けないといけないという教訓でした。