Search code examples
aws-code-deployaws-code-deploy-appspec

appspec.yml is unable to run the script


I am unable to run the script mentioned in appspec.yml file for my node.js project. Have provided the execute permission to the runas user too. Also, changing the runas to ec2-user is not helping since the script is running with root user only. Codedeploy is able to deploy the artifacts at specified location on my ec2 server without any errors. Could someone help me with this issue. (Want to try it with Beanstalk afterwards but that too needs appspec.yml file to work !!)

appspec.yml File

version: 0.0  
os: linux  
files:  
  - source: /  
    destination: /opt/dev  
permissions:
  - object: /opt/dev/scripts/UnzipResourceBundle.sh
    mode: 777
    owner: root
    type:
      - file  

hooks:  
  AfterInstall:  
    - location: scripts/UnzipResourceBundle.sh  
      timeout: 1800  
      runas: root 

UnzipResourceBundle file locations and permissions (in codedeploy agent deployment folder):

/opt/codedeploy-agent/deployment-root/7f8a2414-b048-4468-a3f5-74efa04371c7/d- 
G7FCROQS2/deployment-archive/scripts/UnzipResourceBundle.sh


-rwxr-xr-x 1 root root 532 Feb 27 08:07 UnzipResourceBundle.sh

UnzipResourceBundle.sh file:

shebang : #!/bin/bash  
script runs the forever service and migrates db scripts.

Solution

  • I resolved it by creating the shell script in linux server and then comitting it to codecommit. I had created the file on Windows machine and they were created in DOS format so EC2 OS was unable to find or execute the script file since it was looking for unix format.So, One needs to create file in Unix format to excute it. My codepipeline is working fine now !!