24

so I have been trying to setup code deploy for my application, but it keeps on failing. Initially, I didn't have an appspec.yml file in repository, so I got the error message that the appspec.yml file doesn't exist.

I have now included an appspec.yml file, but it still doesn't work and it doesn't give any error message. There are no events mentioned, like it used to before adding the appspec file.

I have less than a beginner's knowledge when it comes to creating a appspec.yml file, but I took hint from a youtube tutorial, and here is the file.

version: 0.0
os: linux
files:
 - source: /
   destination: /var/www/cms

If it helps, the ec2 instance is running an ubuntu server, /var/www/cms is that directory out of which the nginx is supposed to serve files.

1
  • 3
    Check code deploy agent is running on the instance. Also, you can check the code deploy agent logs on the Ubuntu ec2 instance for more information, perhaps the error is in there: /var/log/aws/codedeploy-agent Lastly, you can also check specific deployment steps here: less +F /opt/codedeploy-agent/deployment-root/{deployment-group-ID}/{deployment-ID}/logs/scripts.log Commented Jun 15, 2017 at 18:09

4 Answers 4

46

The most likely problem you're facing is that the agent either isn't installed or the instance doesn't have sufficient permissions. When there are no events started on the instance for the deployment, it means that CodeDeploy couldn't talk to the host for some reasons.

Here's the steps I would take:

  1. Confirm that you installed the CodeDeploy agent
  2. Confirm that you've created the IAM service role
  3. Confirm that you have the IAM Instance Profile and that it's associated with the instance
  4. Check that you can reach the CodeDeploy commands endpoint in your region from the box. i.e. ping codedeploy.us-east-1.amazonaws.com Otherwise, your networking setup might be too restrictive.
  5. Look at the logs on the host to see what's going on
5
  • 2
    in my case, it was wrong Security groups (does not allow to do HTTP call) Commented Jun 27, 2019 at 8:49
  • 2
    @StepanSuvorov That's a good point. Setting up security groups properly can be tricky. Updated answer to check that. Commented Jun 28, 2019 at 15:13
  • Life saver dude!
    – AhmadWabbi
    Commented Oct 31, 2019 at 0:43
  • 3
    In my case, after associating the IAM Instance Role to the Instance, a restart of the CodeDeploy agent service fixed the issue (on Ubuntu 18). Thanks!
    – SebaGra
    Commented Apr 20, 2020 at 9:49
  • @SebaGra - sometimes you stumble upon comments that you know have saved you 4 hours of pain and misery, so from the bottom of my heart, thank you.
    – koosa
    Commented Oct 14, 2020 at 1:37
20

I faced at sometime this thing and it was due to the following: If we initially created and turned on the ec2 instance without setting the IAM service role, and after that we added the service role, it will not take effect until we restart the instance.

3
  • 5
    After more than 5 hours of troubleshooting, this solved my problem. Thank you. Commented Jul 14, 2020 at 17:13
  • same here, after 3-4 hours of a struggle this solution has worked for me. AWS should have mentioned this somewhere in their documentation.
    – umer
    Commented Dec 25, 2020 at 18:45
  • Thank you so much! I could not even imagine that editing the IAM role later caused my problem.
    – James Yoo
    Commented Apr 22, 2021 at 5:46
1

In case it helps, I had the same problem and the reason was that codedeploy agent was not installed in the ec2 instance. After installing it, everything worked like a charm.

0

I had attached IAM role to EC2 instance but I did not restart my systemd service. And that was the cause of failure.

Also, without rebooting instance, you can just restart systemd service of codedeploy-agent.

Not the answer you're looking for? Browse other questions tagged or ask your own question.