LoNormaly
LoNormaly

Reputation: 11

How to deploy existing app with CodeDeploy on a new EC2 instance

I use CodeShip to deploy my app to AWS EC2 instances when a new app version is out. CodeShip first packages my app into .zip and puts it in S3. Each deployment package is being generated with different file name. When I deploy with CodeShip, they create a new revision in CodeDeploy and deploys it to all current instances.

On the one direction, every time I deploy new version it's being deployed to all my already up instances, but how can I deploy the latest revision of my app from CodeDeploy to the new born instance? Is there any way using the aws-sdk (Ruby or cli) to achieve this?

I use OpsWorks to maintain my instances and I use custom Chef cookbook to build the environment.

Thanks

Upvotes: 1

Views: 1786

Answers (2)

Calvin Boey
Calvin Boey

Reputation: 341

Since you have a group of EC2 instances which you wish to have the same application running, consider to use the AutoScaling Group (ASG). Then, create a deployment group based on the ASG (not EC2 instance tags). Next time when any new machine is launched in this ASG, Code Deploy will automatically run and deploys the last successful deployment package. I've been using this method for many months now and it works perfectly.

Upvotes: 2

Bangxi Yu
Bangxi Yu

Reputation: 191

From CodeDeploy http://aws.amazon.com/codedeploy/faqs/ , if you go to the concepts section and look at question "What is a deployment group" , in the answer you will get more idea about how deployment group works.

CodeDeploy uses the tags in the deployment group to find EC2 instances when creating a new deployment. So for new born instances, basically you just need to tag them with the same tag(s) in that deployment group, and then kick off a new deployment with the revision you want. CodeDeploy will find all the EC2 instances that are tagged with the tags in the deployment group.

But you should notice this, if you want to manually start up a new EC2 instance, there are several things you need to do. You can follow the steps here: http://docs.aws.amazon.com/codedeploy/latest/userguide/how-to-prepare-instances.html to launch a instance that works with CodeDeploy.

After the instance has been tagged and set up correctly, you can just kick off a new deployment with the latest revision as the current way you do it. The revision should be deployed to the new instance by CodeDeploy automatically.

Upvotes: 1

Related Questions