Deciphering AWS CodeDeploy's config and appspec pathing

416 views Asked by At

I have an appspec.yml file sitting in the root of a revision (artifact) I am deploying from CodeCommit:

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ec2-user/app/aws
file_exists_behavior: OVERWRITE
hooks:
  ApplicationStart:
    - location: /home/ec2-user/app/aws/update_wheel.sh
      timeout: 300
      runas: root

I changed my codedeployagent.yml on my ec2 instance (in order to deal with this issue; changing the :root_dir: manually is not an ideal solution, even if it were to have worked):

/etc/codedeploy-agent/conf/codedeployagent.yml
---
:log_aws_wire: false
:log_dir: '/var/log/aws/codedeploy-agent/'
:pid_dir: '/opt/codedeploy-agent/state/.pid/'
:program_name: codedeploy-agent
:root_dir: '/home/ec2-user/'
:verbose: false
:wait_between_runs: 1
:proxy_uri:
:max_revisions: 2

But I am still getting errors like this:

/home/ec2-user/app/aws/update_wheel.sh
Script does not exist at specified location: /home/ec2-user/xxxxxx-cb84-4ef6-966b-xxxxxxxxx/d-xxxxx/deployment-archive/home/ec2-user/app/aws/update_wheel.sh

I don't really understand why I am copying files to a destination and then not expected to be using those files, or why I shouldn't expect those (shell script) files to use their original pathing. To what destination should I be copying the source files and why can I not get hooks to expect the :root_dir I set in the codeagent config?

1

There are 1 answers

0
Marcin On

The location is always with respect to your bundle:

. The location in the bundle of the script file for the revision. The location of scripts you specify in the hooks section is relative to the root of the application revision bundle.

Since you changed it to root_dir: '/home/ec2-user/' all deployments will be stored in that folder. This requires the use of Deployment ID and Execution ID values specific to CodeDeploy.

Thus you should still use only relative paths to the bundle. You can try with:

location: run_in_home_folder.sh

where run_in_home_folder.sh is

#!/bin/bash

cd /home/ec2-user/app/aws && sh ./update_wheel.sh