Rollback机制

CodeDeploy的回滚,需要将之前的版本当作一个新的部署来进行。回滚到的之前的版本,从技术上体现为部署成新版本,因为它有新的deployment ID

可以通过手动或自动的方式将部署进行回滚,当部署失败或者监控达到阈值时,回滚到上一个版本

Rollback behavior with existing content

You might choose to retain files that you want to be part of the next deployment without having to add them to the application revision package. For example, you might upload files directly to the instance that are required for the deployment but weren’t added to the application revision bundle. Or you might upload files to the instance if your applications are already in your production environment but you want to use CodeDeploy for the first time to deploy them.

In the case of rollbacks, where the most recent successfully deployed application revision is redeployed due to a deployment failure, the content-handling option for that last successful deployment is applied to the rollback deployment.

However, if the deployment that failed was configured to overwrite, instead of retain files, an unexpected result can occur during the rollback. Specifically, the files you expected to be retained might be removed by the failed deployment. The files are not on the instance when the rollback deployment runs.

In the following example, there are three deployments. Any file that is overwritten (deleted) during the failed second deployment is no longer available (cannot be retained) when application revision 1 is deployed again during deployment 3:

Deployment Application revision Content overwrite option Deployment status Behavior and result
deployment 1 application revision 1 RETAIN Succeeded CodeDeploy detects files in the target locations that were not deployed by the previous deployment. These files might be placed there intentionally to become part of the current deployment. They are kept and recorded as part of the current deployment package.
deployment 2 application revision 2 OVERWRITE Failed During the deployment process, CodeDeploy deletes all the files that are part of the previous successful deployment. This includes the files that were retained during deployment 1.However, the deployment fails for unrelated reasons.
deployment 3 application revision 1 RETAIN Because auto rollback is enabled for the deployment or deployment group, CodeDeploy deploys the last known good application revision, application revision 1.However, the files that you wanted to retain in deployment 1 were deleted before deployment 2 failed and cannot be retrieved by AWS CodeDeploy. You can add them to the instance yourself if they are required for application revision 1, or you can create a new application revision.

实践

image-20221002140521233

image-20221002140753634

image-20221002140848288