

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用部署策略
<a name="appconfig-creating-deployment-strategy"></a>

部署策略使您能够在几分钟或几小时内缓慢发布对所有目标或特定细分的更改，可以基于会话，也可以利用基于实体的部署，沿着自己的目标维度发布更改。

**注意**  
AWS AppConfig 代理（版本 2.0.136060 或更高版本）支持在逐步推出期间将功能标志或自由格式配置数据部署到特定细分市场或个人用户。基于实体的渐进部署可确保用户或分区收到配置版本后，无论哪种计算资源为其请求提供服务，他们都可以在整个部署期间继续收到相同的版本。有关更多信息，请参阅 [使用 AWS AppConfig 代理进行基于用户或实体的渐进部署](appconfig-agent-how-to-use.md#appconfig-entity-based-gradual-deployments)。

 AWS AppConfig 部署策略定义了配置部署的以下重要方面。


****  

| 设置 | 说明 | 
| --- | --- | 
| 运行时间 | 部署进度 | 
| --- | --- | 
|  部署类型  | *部署类型定义了配置的部署或部署方式。* AWS AppConfig 支持**线性和****指数**部署类型。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/appconfig/latest/userguide/appconfig-creating-deployment-strategy.html)  | 
|  步骤百分比（增长系数）  |  该设置指定在部署的每个步骤中作为目标的调用方百分比。  在开发工具包和 [AWS AppConfig API 参考](https://docs.aws.amazon.com/appconfig/2019-10-09/APIReference/API_CreateDeploymentStrategy.html)中，`step percentage` 称为 `growth factor`。   | 
|  Deployment time (部署时间)  |  此设置指定 AWS AppConfig 部署到主机的时间。这不是超时值。这是一个按间隔处理部署的时段。 | 
|  烘焙时间  |  此设置指定在将配置部署到 100% 的目标之后，在考虑部署已完成之前， AWS AppConfig 监控 Amazon CloudWatch 警报的时间长度。如果在此期间触发了警报， AWS AppConfig 将回滚部署。您必须配置权限 AWS AppConfig 才能根据 CloudWatch 警报进行回滚。有关更多信息，请参阅 [配置自动回滚的权限](setting-up-appconfig.md#getting-started-with-appconfig-cloudwatch-alarms-permissions)。  | 
|  0 小时  |  0%  | 
|  2 小时  |  20%  | 
|  4 小时  |  40%  | 
|  6 小时  |  60%  | 
|  8 小时  |  80%  | 
|  10 小时  |  100%  | 

您可以选择随附的预定义策略， AWS AppConfig 也可以创建自己的策略。

**注意**  
AWS AppConfig 代理（版本 2.0.136060 或更高版本）支持在逐步推出期间将功能标志或自由格式配置数据部署到特定细分市场或个人用户。基于实体的渐进部署可确保用户或分区收到配置版本后，无论哪种计算资源为其请求提供服务，他们都可以在整个部署期间继续收到相同的版本。有关更多信息，请参阅 [使用 AWS AppConfig 代理进行基于用户或实体的渐进部署](appconfig-agent-how-to-use.md#appconfig-entity-based-gradual-deployments)。

**Topics**
+ [使用预定义部署策略](appconfig-creating-deployment-strategy-predefined.md)
+ [创建部署策略](appconfig-creating-deployment-strategy-create.md)

# 使用预定义部署策略
<a name="appconfig-creating-deployment-strategy-predefined"></a>

AWS AppConfig 包括预定义的部署策略，可帮助您快速部署配置。您可以在部署配置时选择以下选项之一，而不是创建自己的策略。


****  

| 部署策略 | 说明 | 
| --- | --- | 
|  AppConfig.Linear20 6 分钟 PercentEvery  | **AWS 推荐**： 此策略每 6 分钟将配置部署到所有目标的 20%，以进行 30 分钟部署。系统会监控 Amazon CloudWatch 警报 30 分钟。如果此时未收到任何警报，则部署已完成。如果在这段时间内触发了警报，则会回 AWS AppConfig 滚部署。我们建议将此策略用于生产部署，因为它符合 AWS 最佳实践，并且由于其持续时间和烘焙时间长，因此更加重视部署安全。  | 
|  AppConfig.Canary 10% 20 分钟  | **AWS 推荐**： 此策略在 20 分钟内使用 10% 的增长系数以指数方式处理部署。系统将监视 CloudWatch 警报 10 分钟。如果此时未收到任何警报，则部署已完成。如果在这段时间内触发了警报，则会回 AWS AppConfig 滚部署。我们建议将此策略用于生产部署，因为它符合配置部署 AWS 的最佳实践。  | 
|  AppConfig.AllAtOnce  | **快速**： 此策略会立即将配置部署到所有目标。系统将监视 CloudWatch 警报 10 分钟。如果此时未收到任何警报，则部署已完成。如果在此期间触发了警报， AWS AppConfig 将回滚部署。  | 
|  AppConfig.Linear50 30Seconds PercentEvery  | **测试/演示**： 此策略每 30 秒将配置部署到所有目标的一半，以进行一分钟部署。系统会监视 Amazon CloudWatch 警报 1 分钟。如果此时未收到任何警报，则部署已完成。如果在这段时间内触发了警报，则会回 AWS AppConfig 滚部署。我们建议仅将此策略用于测试或演示目的，因为它持续时间和烘焙时间短。  | 

# 创建部署策略
<a name="appconfig-creating-deployment-strategy-create"></a>

如果您不想使用其中一个预定义部署策略，则可以自行创建策略。您最多可以创建 20 个部署策略。在部署配置时，您可以选择最适合应用程序和环境的部署策略。

## 创建 AWS AppConfig 部署策略（控制台）
<a name="appconfig-creating-deployment-strategy-create-console"></a>

使用以下过程通过 AWS Systems Manager 控制台创建 AWS AppConfig 部署策略。

**创建部署策略**

1. 在 [https://console.aws.amazon.com/systems-manager/appconfig](https://console.aws.amazon.com/systems-manager/appconfig/)/上打开 AWS Systems Manager 控制台。

1. 在导航窗格中，选择**部署策略**，然后选择**创建部署策略**。

1. 对于 **Name (名称)**，请输入部署策略的名称。

1. 对于 **Description (描述)**，请输入有关部署策略的信息。

1. 对于 **Deployment type (部署类型)**，选择类型。

1. 对于 **Step percentage (步骤百分比)**，请选择在部署的每个步骤中作为目标的调用方百分比。

1. 对于 **Deployment time (部署时间)**，请输入部署的总持续时间（以分钟或小时为单位）。

1. 在 **Bake** time 中，输入在继续部署的下一步或考虑完成部署之前，监控 Amazon CloudWatch 警报的总时间（以分钟或小时为单位）。

1. 在 **标签** 部分中，输入一个键和可选的值。您最多可以为一个资源指定 50 个标签。

1. 选择 **Create deployment strategy (创建部署策略)**。

**重要**  
如果您为创建了配置文件 AWS CodePipeline，则必须在中创建指定 CodePipeline AWS AppConfig 为*部署提供者的*管道。您不需要执行 [部署配置](appconfig-deploying.md)。但是，您必须配置客户端以接收应用程序配置更新，如 [在没有代理的情况下 AWS AppConfig 检索配置数据](about-data-plane.md) 中所述。有关创建指定 AWS AppConfig 为部署提供者的管道的信息，请参阅《*AWS CodePipeline 用户指南》*中的[教程：创建 AWS AppConfig 用作部署提供者的管道](https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-AppConfig.html)。

继续执行[部署配置](appconfig-deploying.md)。

## 创建 AWS AppConfig 部署策略（命令行）
<a name="appconfig-creating-deployment-strategy-create-commandline"></a>

以下过程介绍如何使用 AWS CLI （在 Linux 或 Windows 上）或 AWS Tools for PowerShell 如何创建 AWS AppConfig 部署策略。

**分步创建部署策略**

1. 打开 AWS CLI.

1. 运行以下命令，创建部署策略。

------
#### [ Linux ]

   ```
   aws appconfig create-deployment-strategy \
     --name A_name_for_the_deployment_strategy \
     --description A_description_of_the_deployment_strategy \
     --deployment-duration-in-minutes Total_amount_of_time_for_a_deployment_to_last \
     --final-bake-time-in-minutes Amount_of_time_AWS AppConfig_monitors_for_alarms_before_considering_the_deployment_to_be_complete \
     --growth-factor The_percentage_of_targets_to_receive_a_deployed_configuration_during_each_interval \
     --growth-type The_linear_or_exponential_algorithm_used_to_define_how_percentage_grows_over_time \
     --replicate-to To_save_the_deployment_strategy_to_a_Systems_Manager_(SSM)_document \
     --tags User_defined_key_value_pair_metadata_of_the_deployment_strategy
   ```

------
#### [ Windows ]

   ```
   aws appconfig create-deployment-strategy ^
     --name A_name_for_the_deployment_strategy ^
     --description A_description_of_the_deployment_strategy ^
     --deployment-duration-in-minutes Total_amount_of_time_for_a_deployment_to_last ^
     --final-bake-time-in-minutes Amount_of_time_AWS AppConfig_monitors_for_alarms_before_considering_the_deployment_to_be_complete ^
     --growth-factor The_percentage_of_targets_to_receive_a_deployed_configuration_during_each_interval ^
     --growth-type The_linear_or_exponential_algorithm_used_to_define_how_percentage_grows_over_time ^
     --name A_name_for_the_deployment_strategy ^
     --replicate-to To_save_the_deployment_strategy_to_a_Systems_Manager_(SSM)_document ^
     --tags User_defined_key_value_pair_metadata_of_the_deployment_strategy
   ```

------
#### [ PowerShell ]

   ```
   New-APPCDeploymentStrategy ` 
     --Name A_name_for_the_deployment_strategy ` 
     --Description A_description_of_the_deployment_strategy `
     --DeploymentDurationInMinutes Total_amount_of_time_for_a_deployment_to_last `
     --FinalBakeTimeInMinutes Amount_of_time_AWS AppConfig_monitors_for_alarms_before_considering_the_deployment_to_be_complete `
     --GrowthFactor The_percentage_of_targets_to_receive_a_deployed_configuration_during_each_interval `
     --GrowthType The_linear_or_exponential_algorithm_used_to_define_how_percentage_grows_over_time `
     --ReplicateTo To_save_the_deployment_strategy_to_a_Systems_Manager_(SSM)_document `
     --Tag Hashtable_type_User_defined_key_value_pair_metadata_of_the_deployment_strategy
   ```

------

   系统将返回类似于以下内容的信息。

------
#### [ Linux ]

   ```
   {
      "Id": "Id of the deployment strategy",
      "Name": "Name of the deployment strategy",
      "Description": "Description of the deployment strategy",
      "DeploymentDurationInMinutes": "Total amount of time the deployment lasted",
      "GrowthType": "The linear or exponential algorithm used to define how percentage grew over time",
      "GrowthFactor": "The percentage of targets that received a deployed configuration during each interval",  
      "FinalBakeTimeInMinutes": "The amount of time AWS AppConfig monitored for alarms before considering the deployment to be complete",
      "ReplicateTo": "The Systems Manager (SSM) document where the deployment strategy is saved"
   }
   ```

------
#### [ Windows ]

   ```
   {
      "Id": "Id of the deployment strategy",
      "Name": "Name of the deployment strategy",
      "Description": "Description of the deployment strategy",
      "DeploymentDurationInMinutes": "Total amount of time the deployment lasted",
      "GrowthType": "The linear or exponential algorithm used to define how percentage grew over time",
      "GrowthFactor": "The percentage of targets that received a deployed configuration during each interval",  
      "FinalBakeTimeInMinutes": "The amount of time AWS AppConfig monitored for alarms before considering the deployment to be complete",
      "ReplicateTo": "The Systems Manager (SSM) document where the deployment strategy is saved"
   }
   ```

------
#### [ PowerShell ]

   ```
   ContentLength               : Runtime of the command
   DeploymentDurationInMinutes : Total amount of time the deployment lasted
   Description                 : Description of the deployment strategy
   FinalBakeTimeInMinutes      : The amount of time AWS AppConfig monitored for alarms before considering the deployment to be complete
   GrowthFactor                : The percentage of targets that received a deployed configuration during each interval
   GrowthType                  : The linear or exponential algorithm used to define how percentage grew over time
   HttpStatusCode              : HTTP Status of the runtime
   Id                          : The deployment strategy ID
   Name                        : Name of the deployment strategy
   ReplicateTo                 : The Systems Manager (SSM) document where the deployment strategy is saved
   ResponseMetadata            : Runtime Metadata
   ```

------