Required. 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. For more information, see Plan a revision for CodeDeploy.
This is why your seeing the error
What you are trying to do I believe is execute a file that is already located on the file system. However, in the appspec file you are referencing files in the package relative to the package root i.e. /opt/codedeploy-agent/deployment-root/deployment-group-id/deployment-id/deployment-archive
So when you try and execute a file defined in the appspec
/mnt/admin/scripts/cd_p6_update.sh what your actually executing is
You have 2 options
- Copy your cd_p6_update.sh over with each deployment and execute with appspec as you are doing now. At least doing it this way you can update this script if you ever need to change it
- Have a script in your your package copied each time that when execute, excutes the existing file located on the machine
As you rightly pointed out, your Yaml is incorrect.. Please try the following.. Im not a fan of Yaml :-)
Hopefully this resolves your issue. Great idea moving to codedeploy to automate the deployment.. You could explore codepipline at some point if you want to add multi steps in there like a blue/green deployment also at the same time
2 x Usefull sites to validate your YAML..
version: 0.0 os: linux files: - source: /code.war destination: /tmp file_exists_behavior: OVERWRITE hooks: BeforeInstall: - location: /mnt/admin/scripts/cd_prepare.sh timeout: 30 runas: root AfterInstall: - location: /mnt/admin/scripts/cd_p6_update.sh timeout: 600 runas: root
Ah that page is excellent (now bookmarked)!
Already have that in a code pipeline, so when there is a commit to codecommit, it will deploy using a pipeline, and it did error again, oddly telling me a script is missing; (note I didn't need the BeforeInstall) so its really just this now;
version: 0.0 os: linux files: source: / destination: /tmp file_exists_behavior: OVERWRITE hooks: AfterInstall: location: /mnt/admin/scripts/cd_p6_update.sh timeout: 600 runas: root
And it's failing with the error:
/mnt/admin/scripts/cd_p6_update.sh Message Script does not exist at specified location: /opt/codedeploy-agent/deployment-root/796c9472-334e-495b-ab5a-2840f73a2c04/d-EC4M8D1LO/deployment-archive/mnt/admin/scripts/cd_p6_update.sh
Oddly the appspec has the full path "location: /mnt/admin/scripts/cd_prepare.sh" but its looking here '/opt/codedeploy-agent/deployment-root/796c9472-334e-495b-ab5a-2840f73a2c04/d-T0QR7D1LO/deployment-archive/mnt/admin/scripts/cd_prepare.sh"
The code.war does appear in the /tmp folder (which is 1/2 the battle), now just need to know why its trying to run the script from that location, is something wrong with that as well?
There’s a simple explanation to that. Will follow up shortly with an answer as I can format correctly
- How do I add parameters when registering an Automation task with Systems Manager maintenance windows?AWS OFFICIALUpdated 2 years ago
- How do I resolve the error that I receive in AWS CodeDeploy when my deployment times out while waiting for a status callback?AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 5 months ago
- EXPERTpublished a month ago
Thanks for that update. I didn't want to have the script, etc. as the developers really just provide that single file, but I guess that is really my only option, but #2 sounds a bit more promising. So if I am understanding #2 the cd_p6_update.sh script could be put into the package, would land in /tmp and when executed had access to the filesystem, it could then say run /scripts/newscript that did everything, that would be a decent solution. The core reason is you need credentials that you can't pass in a script and must be read from a file, so I didn't want all of that in the code, so I will play a bit more, but this was a big help and appreciate the time you put in to help me understand that!
Your most welcome... So long as you have a script in the package to call another script already on the system that should do it.. What you could do is store that password in Parameter store or secret manager and grab the secure password each time the script ran so you dont have to worry about storing sensitive information in code yet be able to script it all..