1
votes

I am implementing Amazon EC2 Auto Scaling and AWS CodeDeploy (blue green deployment). I have assigned a baked AMI to the Auto Scaling group.

Auto Scaling works with no problem without CodeDeploy.

AWS CodeDeploy for blue green deployment works with no problem. I have assigned the autoscaling group in the deployment group.

However, In order to test Blue Green deployment, I terminate one of the instances manually so that Auto Scaling can launch one more instance. However, the instance starts and terminates abruptly.

I see that AWS CodeDeploy has an error:

The deployment failed because a specified file already exists at this location: webserver/server.js

The AWS CodeDeploy configuration I am using is OneAtTime and content options: Overwrite the content.

I only have 1 deployment group for the application.

Currently, I have removed the Auto Scaling group from the AWS CodeDeploy by changing the "Automatically copy Amazon EC2 Auto Scaling group" to "Manually provision instances", which has stopped terminating the instances. However, the new instance created by Auto Scaling does not have the new code. Does CodeDeploy not update or replace the AMI with the new code?

Questions:

  1. Why do I get the error "The deployment failed because a specified file already exists at this location: webserver/server.js"?

  2. The EC2 instance created from autoscaling does not have the latest deployment code?

  3. Is there a better approach to do blue green deployment and autoscaling. or any issues with the above approach?

I have read the AWS CodeDeploy tutorial but have missed something.

1
facing the same issue have you got any solution on this.mahendra rathod

1 Answers

-1
votes

You can use a custom script to cleanup the destination folder and run it from AppSpec hooks section , for example, the lifecycle event BeforeInstall looks like a good place to run this script. You could create an appspec hook called "BeforeInstall" that will clean up the directory that need to be deployed.

For example:

version: 0.0
os: linux
files:
  - source: /
    destination: /var/www/html
hooks:
  BeforeInstall:
    - location: ./cleanup.sh

and the content of cleanup.sh is similar to like this:

#!/bin/bash -xe
# cleanup folder /var/www/html
rm -rf /var/www/html

With this hooks, before your code is deployed, BeforeInstall hook will run and that script will be executed to clean up the directory.

More information about appspec hook can be found here: http://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html