6

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.

antpaw
  • 13,658
  • 9
  • 54
  • 83

1 Answers1

6

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.

TimB
  • 1,141
  • 5
  • 7
  • Thanks, is it possible to do the rollback from the pipeline ui? Or do I need to manually figure out what the random folder name was and set it in CloudFormation? – antpaw Sep 09 '17 at 19:49
  • To manually trigger a rollback you can cancel the stack update. There is an option in the RollbackConfiguration of your CloudFormation stack for how long to wait. Ideally your CloudWatch alarms would encompass all of your rollback criteria though, so rollbacks would be automatic rather than manual. http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn--stack-update-cancel.html – TimB Sep 11 '17 at 16:31