Reputation: 21
Does AWS CloudFormation support blue/green deployments for EC2? I was able to create blue/green deployment using CodeDeploy for EC2; however, I couldn't figure out how to create one using CloudFormation. It appears that CloudFormation supports blue/green deployment for ECS (https://aws.amazon.com/about-aws/whats-new/2020/05/aws-cloudformation-now-supports-blue-green-deployments-for-amazon-ecs/) and Lambda functions.
The CodeDeploy section of the template looks like this:
Type: AWS::CodeDeploy::DeploymentGroup
Properties:
DeploymentGroupName: 'SampleGroupName'
ServiceRoleArn: !Sub 'arn:aws:iam::${AWS::AccountId}:role/AzureDevOps/CodeDeployOperations'
ApplicationName: !Ref CodeDeployApplication
AutoScalingGroups:
- !Ref SampleASG
DeploymentStyle:
DeploymentType: BLUE_GREEN
DeploymentOption: WITH_TRAFFIC_CONTROL
BlueGreenDeploymentConfiguration:
TerminateBlueInstancesOnDeploymentSuccess:
Action: TERMINATE
TerminationWaitTimeInMinutes: 5
DeploymentReadyOption:
ActionOnTimeout: CONTINUE_DEPLOYMENT
GreenFleetProvisioningOption:
Action: COPY_AUTO_SCALING_GROUP
DeploymentConfigName: !If [IsProdStaging, CodeDeployDefault.HalfAtATime, CodeDeployDefault.AllAtOnce]
LoadBalancerInfo:
TargetGroupInfoList:
- Name: !GetAtt SampleTargetGroup.TargetGroupName
AutoRollbackConfiguration:
Enabled: true
Events:
- DEPLOYMENT_FAILURE
Upvotes: 2
Views: 2933
Reputation: 71
Actually there is a workaround that should be rather easy if you use CloudFormation to set up your EC2s with necessary infra. With CloudFormation you can create a second stack with new release on it, that is so-called green stack. For gradual release, you can:
Example case
E.g. let's say that you have a stack with Auto Scaling Group (ASG) and load balancer. Your service DNS name myservice.com routes to Elastic IP (EIP) that was attached to your load balancer. To deploy a new release, you will just have to change the AMI id for your ASG.
OPTION 1
Of course, this solution might cause a lot of problems and is not blue green in a sense that DNS cache will cause disruptions for cache validation period even if the new broken release has been taken down. Thus, I think using load balancer is a better solution.
OPTION 2
GENERAL In each case, you most likely want to parametrise some values to make it easy to change the load gradually and to automate the whole process. To automate the whole deployment process, you would most likely use some CloudWatch or EventBridge rules and Lambdas if necessary, depending mostly on your needs and practices. This should not be very difficult
Upvotes: 1
Reputation: 931
As of now (Oct 2021), AWS still doesn't support Blue/Green deployments via CloudFormation if you are using EC2. There is a blue note in the DeploymentStyle
section of the docs, reading:
For blue/green deployments, AWS CloudFormation supports deployments on Lambda compute platforms only. You can perform Amazon ECS blue/green deployments using AWS::CodeDeploy::BlueGreen hook.
It is super frustrating that this is not available, as there are no good workarounds.
Upvotes: 3