Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add rollback functionality to a basic S3 CodeBuild deploy

I have followed this instruction to get a very basic ci workflow in aws. It works flawless but I want to have a extra functionality, rollback. First i though it would work "out-of-the-box", but not in my case, if I select the the previous job in CodeBuild that i want to rollback to and hit "Retry" i get this error message: "Error ArtifactsOverride must be set when using artifacts type CodePipelines". I have also tried to rerun the whole pipeline again with pipeline history page, but it's just a list of builds without any functionality.

My questions is: how to add a rollback function to my workflow. It doesn't have to be in the same pipeline etc. But it should not touch git.

like image 987
antpaw Avatar asked Sep 03 '17 16:09

antpaw


People also ask

Can you rollback a CodeDeploy deployment?

CodeDeploy rolls back deployments by redeploying a previously deployed revision of an application as a new deployment. These rolled-back deployments are technically new deployments, with new deployment IDs, rather than restored versions of a previous deployment. Deployments can be rolled back automatically or manually.

What is rollback deployment?

A rollback is getting back to a known good state by running a modified version of the original deployment process.

How do I roll back AWS?

Open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation . Select the stack that you want to update, choose Stack actions, and then choose Continue update rollback.

How can you quickly roll back to the previous version of your code in AWS?

In the AWS Management Console, go to the Lambda console. Search for the Lambda that you want to roll back and click the function name. Open the function's Version tab. To go back to a previous version of a Service Cloud Voice Lambda, edit the Active Alias.


1 Answers

AWS CloudFormation now supports rolling back based in a CloudWatch alarm.

I'd put a CloudFront distribution in front of your S3 bucket with the origin path set to a folder within that bucket. Every time you deploy to S3 from CodeBuild you deploy to a random new S3 folder.

You then pass the folder name in a JSON file as an output artifact from your CodeBuild step. You can use this artifact as a parameter to a CloudFormation template updated by a CloudFormation action in your pipeline.

The CloudFormation template would update the OriginPath field of your CloudFront distribution to the folder containing your new deployment.

If the alarm fires then the CloudFormation template would roll back and flip back to the old folder.

There are several advantages to this approach:

  • Customers should only see either the new or old version while the deployment is happening rather than seeing potentially mixed files while the deployment is running.
  • The deployment logic is simpler because you're uploading a fresh set of files every time, rather than figuring out which files are new and which need to be deleted.
  • The rollback is pretty simple because you're flipping back to files which are still there rather than re-deploying the old files.

Your pipeline would need to contain both the CodeBuild and a sequential CloudFormation action.

like image 183
TimB Avatar answered Sep 22 '22 16:09

TimB