How to keep TaskDefinitions in sync with the CloudFormation template that created them when CodeDeploy is used?

0

I was able to set up a full ECS Service stack with Blue/Green deployments using CloudFormation. The stack includes the load balancer (with listeners and target groups), an ECS Cluster, an ECS Service, a Task Definition, a Deployment Group, and CodeDeploy Application. Everything works great, but now that I have my TaskDefinition, I can't update it via CloudFormation without getting the following error:

Unable to update task definition on services with a CODE_DEPLOY deployment controller.  Use AWS CodeDeploy to trigger a new deployment.

That's straight-forward enough, I can update the TaskDefinition manually with a new revision that contains the changes I need (I simply added an environment file to a container definition) and do a new deploy using the new revision. However, now my CloudFormation template is out of sync with my resources, and I am unable to use it to make further modifications. Even if I make the same changes to the template that I made manually to the TaskDefinition, CloudFormation is still confused and thinks it needs to do something.

One workaround I tried was editing my template to completely remove the TaskDefinition, ECS Service, and Deployment Group. Run that as an update, and then put them all back in (with the modified version of the TaskDefinition) and run a second update. That seemed to work ok, but now I am getting false positives on my Drift Detection results regarding the changes I made to the TaskDefinition. (The Drift Detection says the "expected" value is that the container should contain the environment file - which is the correct "expected" value - but the "actual" value is reporting as missing. However, when I look at the actual TaskDefinition it is pointing to, it clearly has the environment file that Drift Detection says is missing.)

1 Answer
0

Hello,

Hope you are doing good.

I understand that you are looking for a way to keep the task definition in sync with CloudFormation when performing Blue/Green deployment for ECS service. To achieve this use case, CodeDeploy supports performing Blue/Green deployment via CloudFormation as shown here : https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/blue-green.html#blue-green-resources

CloudFormation uses Transform to perform deployment and it checks changes to the resource AWS::ECS::TaskDefinition and AWS::ECS::TaskSet to perform a new deployment.

Can you please confirm if you are using this method to perform and manage Blue/Green deployment for ECS ? If yes, then I would request you to please open a new support case with AWS and we would be able to further troubleshoot the issue you are facing.

AWS
answered 9 months ago
  • Thanks for the response - no I am not using CloudFormation to perform the blue/green deployment, as I was having trouble getting it working with CodePipeline and/or AWS CLI. My end goal was to trigger deployments to AWS from our on-site continuous build environment. I was thinking the build tool could push a new image to ECR, and either do a blue/green deployment with a create-deployment command, or have CodePipeline automatically pick it up and initiate the deployment. I was able to accomplish both of these workflows by using CF to create an ECS Service with CODE_DEPLOY as the deployment controller. As I was reading the documentation on blue/green deployments initiated by CloudFormation, it sounded like I would have to manually update the CloudFormation template to swap out the TaskSet and then do a stack update. Maybe I am misreading something about the way blue/green deployments work with CloudFormation?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions