8

The CodeDeploy agent did not find an AppSpec file within the unpacked revision directory at revision-relative path "appspec.yml".

The revision was unpacked to directory "/opt/codedeploy-agent/deployment-root/0bb5a5aa-5894-4575-a69c-a7a4e79b4cdf/d-HQ5GBC7SW/deployment-archive"

The AppSpec file was expected but not found at path "/opt/codedeploy-agent/deployment-root/0bb5a5aa-5894-4575-a69c-a7a4e79b4cdf/d-HQ5GBC7SW/deployment-archive/appspec.yml".

Natalie Hedström
  • 2,607
  • 3
  • 25
  • 36
Raghuram Milkuri
  • 81
  • 1
  • 1
  • 3

6 Answers6

14

I had the same problem and the other answer helped me reach the right conclusion. In my situation, I had the appspec.yml file in my git repo, but I forgot to add it to the artifact files section. As a result, the appspec.yml wasn't included in the zip and so the deployment step couldn't find it.

In your buildspec.yml, add:

artifacts:
  files:
    - appspec.yml
    - ... other files to include in your build ...

I had some other errors in my deployment configuration too. Looking at the bottom of the log file helped discover them:

less /var/log/aws/codedeploy-agent/codedeploy-agent.log

At one point, my EC2 instance also hung when trying to run a deployment and stopping and restarting the codedeploy agent didn't help. I had to completely restart the EC2 instance.

These docs where helpful: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html

Allen
  • 2,717
  • 2
  • 30
  • 34
  • 2
    This was my problem too. I had to add it as an artifact in my buildspec.yml – Sam Orozco Nov 03 '20 at 02:43
  • That fixed it for me! Also don't forget to include any other scripts that are called from the appspec file. – abk Sep 25 '22 at 00:11
  • don't forget to include any other files that your `appspec.yml` file needs to run like start sripts. – d512 Jan 10 '23 at 22:39
6

Are you putting the appspec.yml file at root level of your folder bundle? If yes, how are you creating the bundle? If you are just creating a .zip then you need to make sure you are adding the files to the zip instead of a folder.

Aura Herrera
  • 246
  • 1
  • 6
  • 1
    thanks for the pointing the exact issue. One should zip files instead of doing zip to a directory containing those files. – ScanQR Apr 28 '20 at 08:56
5

#It seems to have a successful deployment at some point of time.

It's looking for the most recent deployment and if it's not available above error will occur.

Go into /opt/codedeploy-agent/deployment-root/deployment-instructions/ and delete all the files in there. #Then it won't look for this last deploy.

  • 1
    I've been stuck on the same build for hours. This fixed my issues. – Julian Feb 04 '23 at 05:14
  • Researching further, ensuring that the "file-exists" behavior is set to overwrite fixed my issue: https://stackoverflow.com/a/71434183/4342481 – Julian Feb 04 '23 at 05:47
  • I had deleted some of the old deployment folders from C:\ProgramData\Amazon\CodeDeploy to free up drive space. The error message in CodeDeploy console was useless: Unknown Error, CodeDeploy agent was not able to receive the lifecycle event. In the codedeploy-agent-log.txt the error message was: "The CodeDeploy agent did not find an AppSpec file within the unpacked revision directory at revision-relative path..." but that path did not exist because I had deleted it. Once I deleted all files in C:\ProgramData\Amazon\CodeDeploy\ongoing-deployment my deployment was successful. – Matthew Allen May 23 '23 at 20:31
  • This worked for me as well. – Eternal21 Aug 02 '23 at 19:43
1

Adding onto Aura's answer which solved it for me. Thank you again Aura! For mac users:

To create a zip with all of the files, open up the folder you want to zip in finder, highlight all of files (use command A), right click and then select "Compress XYZ items".

The mistake you might be making is right clicking on the folder itself and clicking "Compress FolderName".

The problem with compressing the entire folder is that the "unpacked directory" ends up being a directory itself. Hence, when the CodeDeploy agent goes looking for the appspec.yml file, it will see something like this "FolderName/" rather than the contents of the FolderName (which should include an appspec.yml).

Hope this extra detail helps.

rishikarri
  • 3,462
  • 2
  • 13
  • 13
1

Issue can be fixed by:

  1. Edit your aws codepipeline.
  2. Edit the codedeploy configuration.
  3. select "SourceArtifact" in input artifacts. (This will deploy all the source code to your desired server and location along with appspec.yml file.)
Prakhar
  • 11
  • 1
0

Not the most useful answer. But I had this problem as well as codebuild could not find the scripts defined in appspec.yml I spent a whole day and then at the end just started rebooted the ec2 and it was able to find the scripts.

slipperypete
  • 5,358
  • 17
  • 59
  • 99
  • Those moments when you can't be sure if you're angry or relieved. I have tried this myself... Fingers crossed I have as much success! – kmjb May 18 '20 at 01:01