Restart the CodeDeploy agent after changing IAM profiles

The CodeDeploy Agent needs to restart to see new IAM profiles

I’ve been trying to understand AWS’ CodeDeploy better and migrate a project from Heroku onto AWS. When setting up the EC2 instance I wanted to deploy to, I had forgotten to attach an IAM profile.

An IAM profile is used to pass an IAM role to an EC2 instance, which is a weird way of saying “letting the EC2 instance know what it can and cannot do”.

The deploy was failing, and the logs were suggesting it was because I didn’t have a profile;

  InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Missing credentials - please check if this instance was started with an IAM instance profile

I added a profile via the AWS console and restarted the EC2 instance.

My next deploy failed for the same reason, which I couldn’t quite understand.

Turns out, you have to restart the CodeDeploy agent for it see the changed profile.

Using SSH, connect to the EC2 instance and run sudo service codedeploy-agent restart, letting it see the new profile.


Recent posts View all

Ruby

The best way to test model scopes in Rails

Learn about Rails scopes and how to best test them with both Rspec and Minitest

Ruby

Finding out what called a Ruby method

A quick way to understand what is calling your code using the caller method