What is AWS CodeDeploy?
AWS CodeDeploy is a service that automates code deployments to any instance, including Amazon EC2 instances and instances running on-premises. CodeDeploy makes it easier for you to rapidly release new features, helps you avoid downtime during application deployment, and handles the complexity of updating your applications.
How does it work?
CodeDeploy handles deployment in groups using revisions, revision contains a version of the source files that the Elastigroup will deploy.
Spotinst Elastigroup integrates with CodeDeploy and acts as the infrastructure layer for your CodeDepoly enabling the launch and management of EC2 Spot Instances or even Reserved Instances according to your configuration and specifications right into your deployment groups with the latest changes that you have made.
With that functionality, CodeDeploy is now much more cost effective. This enables you to keep your application highly available and benefit the Spot instances low costs, 80% cheaper than On Demand.
Yossi Zlotnick from Cortex Media: “Spotinst’s CodeDeploy integration provides us the flexibility we need to push code updates several times, each day. We no longer need to update our AMI’s, CodeDeploy keeps our instances updated on the fly and the seamless integration with Spotinst makes it cost effective. Recently we had a large volume of processing, and Elastigroup automatically launched additional 200 instances of our service on AWS with the latest version, nothing was required from our end, once the demand went back to normal, Elastigroup automatically turned off those instances.”
“Now when using Spotinst CodeDeploy integration we can update our code and the instances are being updated on the fly, scaling up, scaling down and a dramatic cost reduction”
Behind the scenes
Here is a step by step review of the actions taken by Elastigroup to continuously keep your instances up to date with AWS CodeDeploy
First Create Elastigroup with your configuration and attach it to your CodeDeploy
- The Elastigroup launches new Spot / On Demand instances.
- Elastigroup creates a new temporary deployment group
- The new deployment groups inherits its configuration from the CodeDeploy “main” deployment group
- Elastigroup adds the new instance to the temporary group.
- Elastigroup initiates a deploy within the temporary deployment group so the new instances will get the latest version.
- Once the deployment is finished successfully, Spotinst will move the new instances from the temporary deployment group to the “main” deployment group
- Removes the temporary deployment group.
In order to activate this integration you need to create the following configuration
1.User Data Startup Script
Use the following User Data startup script in the group configuration. For more information please see: User Data
#!/bin/bash -x REGION=$(curl 169.254.169.254/latest/meta-data/placement/availability-zone/ | sed 's/[a-z]$//') yum update -y yum install ruby wget -y cd /home/ec2-user wget https://aws-codedeploy-$REGION.s3.amazonaws.com/latest/install chmod +x ./install ./install auto
2. Register to Integrations
Scroll down the Compute tab and expand the Integrations section.
Enable CodeDeploy integration and select your application and Deployment group resources.
Note: the application and Deployment group resources should already exist in your AWS account.
- CleanupOnFailure – if this option is checked, we delete the temporary group created. If not, we don’t delete the temporary deployment group in case of failure (so the user can view the logs of the group and the deployment).
- Terminate Instance On Failure – if this option is checked, we terminate the instance that failed. If not, we keep the instances that failed.
That’s it, you are ready to go!