

# REL08-BP05 使用自动化功能部署更改
<a name="rel_tracking_change_management_automated_changemgmt"></a>

 自动执行部署与修补来消除负面影响。

 对许多组织来说，对生产系统进行变更是风险最大的工作之一。除了软件解决的业务问题外，我们认为部署也是亟待解决的首要问题。如今，这意味着根据实际情况在操作中使用自动化，包括测试和部署更改、添加或删除容量以及迁移数据。

 **期望结果：**通过广泛的预生产测试、自动回滚和错开生产部署，将自动化部署安全性融入发布流程。这种自动化尽可能地减少了部署失败对生产造成的潜在影响，开发人员不再需要主动关注部署到生产的情况。

 **常见反模式：**
+  手动执行更改。
+  跳过自动化流程中的步骤，采用手动应急工作流。
+  不遵循既定的计划和流程，急于求成。
+  在不预留烘焙时间的情况下，快速执行了后续部署。

 **建立此最佳实践的好处：**当使用自动化来部署所有更改时，可以消除引入人为错误的可能性，并提供在更改生产环境之前进行测试的能力。在生产推送之前执行此流程，以便验证您的计划是否能完成。此外，自动回滚到发布流程可以识别生产问题，并将您的工作负载恢复到以前的正常工作运行状态。

 **在未建立这种最佳实践的情况下暴露的风险等级：**中 

## 实施指导
<a name="implementation-guidance"></a>

 实现部署管道的自动化。借助部署管道，您可以调用自动化测试和异常检测，并且能够在生产部署前的某个步骤停止管道，或自动回滚更改。其中必不可少的是采用[持续集成和持续交付/部署](https://en.wikipedia.org/wiki/CI/CD)（CI/CD）文化，这样一来，提交或代码更改会经过各种自动化阶段（完成构建和测试，并最终部署至生产环境中）。

 虽然传统观点认为，您应该让人来处理循环中最困难的操作程序，但出于相同的原因，我们建议您将最困难的程序自动化。

### 实施步骤
<a name="implementation-steps"></a>

 您可以按照以下步骤实现自动化部署，从而消除手动操作：
+  **设置代码存储库以安全地存储您的代码：**使用基于 Git 等流行技术的托管源代码管理系统，来存储源代码和基础设施即代码（IaC）配置。
+  **配置持续集成服务来编译源代码、运行测试和创建部署构件：**要为此目的设置构建项目，请参阅 [Getting started with AWS CodeBuild using the console](https://docs.aws.amazon.com/codebuild/latest/userguide/getting-started.html)。
+  **设置部署服务来自动执行应用程序部署并处理复杂的应用程序更新，无需依赖容易出错的人工部署过程：**[AWS CodeDeploy](https://aws.amazon.com/codedeploy/) 可自动将软件部署到各种计算服务，例如 Amazon EC2、[AWS Fargate](https://aws.amazon.com/fargate/)、[AWS Lambda](https://aws.amazon.com/lambda) 和本地服务器。要配置这些步骤，请参阅 [Getting started with CodeDeploy](https://docs.aws.amazon.com/codedeploy/latest/userguide/getting-started-codedeploy.html)。
+  **设置持续交付服务，实现发布管道的自动化，从而带来更快、更可靠的应用程序和基础设施更新：**请考虑使用 [AWS CodePipeline](https://docs.aws.amazon.com/codepipeline/latest/userguide/getting-started-codepipeline.html) 来帮助您实现发布管道的自动化。有关更多详细信息，请参阅 [CodePipeline tutorials](https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials.html)。

## 资源
<a name="resources"></a>

 **相关最佳实践：**
+  [OPS05-BP04 使用构建和部署管理系统](https://docs.aws.amazon.com/wellarchitected/latest/operational-excellence-pillar/ops_dev_integ_build_mgmt_sys.html) 
+  [OPS05-BP10 完全自动化集成和部署](https://docs.aws.amazon.com/wellarchitected/latest/operational-excellence-pillar/ops_dev_integ_auto_integ_deploy.html) 
+  [OPS06-BP02 测试部署](https://docs.aws.amazon.com/wellarchitected/latest/operational-excellence-pillar/ops_mit_deploy_risks_test_val_chg.html) 
+  [OPS06-BP04 自动测试和回滚](https://docs.aws.amazon.com/wellarchitected/latest/operational-excellence-pillar/ops_mit_deploy_risks_auto_testing_and_rollback.html) 

 **相关文档：**
+  [Continuous Delivery of Nested AWS CloudFormation Stacks Using AWS CodePipeline](https://aws.amazon.com/blogs/devops/continuous-delivery-of-nested-aws-cloudformation-stacks-using-aws-codepipeline) 
+  [APN 合作伙伴：可帮助创建自动化部署解决方案的合作伙伴](https://aws.amazon.com/partners/find/results/?keyword=devops) 
+  [AWS Marketplace：可用于自动实施部署的产品](https://aws.amazon.com/marketplace/search/results?searchTerms=DevOps) 
+  [Automate chat messages with webhooks.](https://docs.aws.amazon.com/chime/latest/ug/webhooks.html)
+  [Amazon Builders' Library：确保部署期间安全回滚](https://aws.amazon.com/builders-library/ensuring-rollback-safety-during-deployments) 
+  [Amazon Builders' Library：采用持续交付，加速交付进度](https://aws.amazon.com/builders-library/going-faster-with-continuous-delivery/) 
+  [什么是 AWS CodePipeline？](https://docs.aws.amazon.com/codepipeline/latest/userguide/welcome.html) 
+  [What Is CodeDeploy?](https://docs.aws.amazon.com/codedeploy/latest/userguide/welcome.html)
+  [AWS Systems Manager Patch Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-patch.html) 
+  [What is Amazon SES?](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/Welcome.html)
+  [What is Amazon Simple Notification Service?](https://docs.aws.amazon.com/sns/latest/dg/welcome.html)

 **相关视频：**
+  [AWS Summit 2019: CI/CD on AWS](https://youtu.be/tQcF6SqWCoY) 