CodeDeploy Script does not exist at specified location - appspec.yml - amazon-web-services

I am trying to deploy my app on AWS with CodeDeploy.
Here is my appspec.yml file:
version: 0.0
os: linux
files:
- source: /
destination: /home/ec2-user/todos // <== this dir already exists in my instance
hooks:
ApplicationStop:
...
BeforeInstall:
- location: scripts/prerequisites
timeout: 1200
runas: root
AfterInstall:
...
ApplicationStart:
...
ValidateService:
...
I keep getting the following error:
Error Code: ScriptMissing
Script Name: scripts/prerequisites
Message: Script does not exist at specified location:
/opt/codedeploy-agent/deployment-root/2e557520-7ffe-4881-8c7c-991952c56e05/d-UWR3Z01FE/deployment-archive/scripts/prerequisites
Log Tail: LifecycleEvent - BeforeInstall
My scripts are stored in a file called 'scripts' that is found at the root of my app.
What am I missing? or doing wrong? If anyone could help me in the right direction I would be very grateful!

Ok so it seems that the problem was simply a typo. I forgot to write the file extension to my scripts (.sh)
Like so:
BeforeInstall:
- location: scripts/prerequisites.sh // <--- this fixed it
timeout: 1200
runas: root
Hope it helps anyone.

Related

AWS CodeDeploy to EC2 not updating modified date for files

My deployment is putting the files on the server but all of the files have a modified time of 0 so Apache isn't hosting the updated files.
I added an AfterInstall script that is supposed to touch every file in the directory but it's not working for some reason. There is no error and if I run the script manually it works fine, just not during the deploy process.
Has anyone else run into this issue? Is there something simple I'm overlooking to make this work?
Touch script
#!/bin/bash
find /var/www/html/docs -type f -exec touch {} +
YML file
version: 0.0
os: linux
files:
- source: /source/
destination: /var/www/html/site/
file_exists_behavior: OVERWRITE
permissions:
- object: /var/www/html/site
pattern: "**"
owner: [redacted]
group: [redacted]
hooks:
AfterInstall:
- location: scripts/after_install
timeout: 10
runas: [redacted]

AWS Code Deploy Deployment Failed run as user root failed

i have been use code pipeline and code deploy to deploy my asp.net application using git hub , every time deployment failed with this error message in event log
" Script at specified location: scripts/stop_service run as user root failed with exit code 5 "
i have been installed the Code Deploy Agent on ec2 instance and here is sample from appspec file
version: 0.0
os: linux
files:
- source: /
destination: /var/www/html/
hooks:
BeforeInstall:
- location: scripts/install_dependencies
timeout: 300
runas: root
- location: scripts/start_server
timeout: 300
runas: root
ApplicationStop:
- location: scripts/stop_server
timeout: 300
runas: root
enter image description here
CodeDeploy is trying to run the script 'scripts/stop_server' and failing e.g. because the script is not present at this location.
If the script is at this location, check whats wrong with the execution by inspecting the log at:
/opt/codedeploy-agent/deployment-root/[deployment-group-ID]/[deployment-ID]/logs/scripts.log
Replace '[deployment-group-ID]' and '[deployment-ID]' with actual Ids of your deployment.

can we pass parameters to appsec.yml hook ApplicationStart phase?

I want to deploy my application to aws, I am using codeDeploy for this.
following is my appsec.yml file:
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/project
permissions:
- object: /home/ubuntu/project
owner: root
mode: 777
type:
- directory
hooks:
BeforeInstall:
- location: scripts/install_dependencies.sh
timeout: 900
runas: root
AfterInstall:
- location: ./scripts/after-install.sh
timeout: 900
ApplicationStart:
- location: ./scripts/application-start.sh parameter1 parameter2
timeout: 900
ValidateService:
- location: ./scripts/validate-service.sh
timeout: 900
I am not able to pass paramerters to scripts.
Currently this is not possible.
As a workaround, you can design your Hook Scripts to consume System Environment Variables which can be defined on a instance at launch (through user-data) or you can also retrieve the parameters from AWS SSM Parameter Store (specially if they are secrets) using AWS CLI:
https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-paramstore-cli.html
You can create an if clause using the predefined environment variables. Based on the situation you configure the required values predefined environment variables

codedeploy appspec.yml failed to copy files to destination

appspe.yml script:
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/
permissions:
- object: /home/ubuntu/
owner: root
group: root
mode: 777
hooks:
BeforeInstall:
- location: scripts/install_dependencies.sh
timeout: 300
runas: root
- location: scripts/start_server.sh
timeout: 300
runas: root
ApplicationStop:
- location: scripts/stop_server.sh
timeout: 300
runas: root
Unfortunately, it didn't copy the files to /home/ubuntu/ directory. With this, I am getting the following error while deploying through codedeploy
LifecycleEvent - BeforeInstall Script -
scripts/install_dependencies.sh Script - scripts/start_server.sh
[stderr]cp: cannot stat 'scripts/gunicorn.service': No such file or
directory [stderr]Failed to start gunicorn.service: Unit
gunicorn.service not found. [stderr]Failed to execute operation: No
such file or directory [stderr]Failed to restart gunicorn.service:
Unit gunicorn.service not found. [stderr]cp: cannot stat
'scripts/LIMA': No such file or directory [stderr]ln: failed to create
symbolic link '/etc/nginx/sites-enabled/LIMA': File exists
[stderr]ERROR: Bad port
What went wrong here?
I faced the same issue.
When I moved the commands in the "BeforeInstall" hook to the "AfterInstall" hook it worked for me.
Your errors seem to be of the following categories:
Missing files. ([stderr]cp: cannot stat 'scripts/gunicorn.service': No such file or directory).
Debug: Check if the file actually exists in your deployment bundle. Check the bundle itself and the logs here: less /opt/codedeploy-agent/deployment-root/deployment-group-ID/deployment-ID/. See here
Failure to create symlink because it already exists. ([stderr]ln: failed to create symbolic link '/etc/nginx/sites-enabled/LIMA': File exists). This is not related to file overwrite. Probably there is a 'ln' command somewhere in your script to create the symlink.
Debug: Modify the script to test the symlink for existence and then create it.
I hope this helps.

AWS Code deploy, script failed with exit code 66

I'm using AWS Code Deploy in order to deploy my ASP.NET application into an auto-scaling group.
When deploying i've this error: Script at specified location: application-start.bat failed with exit code 66.
From what i've seen the error code 66 is "The network resource type is not correct", which is very bizzare in this case...
My bundle contains an appspec.yml file like this:
version: 0.0
os: windows
files:
- source: ./
destination: c:\inetpub\wwwroot
hooks:
ApplicationStop:
- location: application-stop.bat
timeout: 900
ApplicationStart :
- location: application-start.bat
timeout: 900
And the bat 2 files (application-stop / application-start) only contains one line each
iisreset /stop
iisreset /start
When i go to the EC2 instance to look at the aws code deploy logs, it's not more clear to me
2016-04-04 08:58:42 ERROR [codedeploy-agent(2848)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: InstanceAgent::Plugins::CodeDeployPlugin::ScriptError - Script at specified location: application-start.bat failed with exit code 66
C:/Windows/TEMP/ocr512.tmp/src/lib/instance_agent/plugins/codedeploy/hook_executor.rb:150:in 'execute_script'
C:/Windows/TEMP/ocr512.tmp/src/lib/instance_agent/plugins/codedeploy/hook_executor.rb:107:in 'block (2 levels) in execute'
Does anyone run into the same issues and find a way to fix it ?