

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

# 在中为您的应用程序创建环境 Amazon AppConfig
<a name="appconfig-creating-environment"></a>

您可以为每个 Amazon AppConfig 应用程序定义一个或多个环境。环境是由 AppConfig 目标组成的逻辑部署组，例如`Production`环境中的应用程序、 Amazon Lambda 函数或容器。`Beta`您也可以为应用程序子组件定义环境，例如应用程序的 `Web`、`Mobile` 和 `Back-end`。您可以为每个环境配置 Amazon CloudWatch 警报。系统在部署配置期间监控警报。如果触发警报，系统将回滚配置。

**开始前的准备工作**  
如果您想启用回滚配置 Amazon AppConfig 以响应 CloudWatch 警报，则必须为一个 Amazon Identity and Access Management (IAM) 角色配置一个 Amazon AppConfig 允许响应 CloudWatch 警报的权限。您可以在以下过程中选择该角色。有关更多信息，请参阅 [配置自动回滚的权限](setting-up-appconfig.md#getting-started-with-appconfig-cloudwatch-alarms-permissions)。

**Topics**
+ [创建 Amazon AppConfig 环境（控制台）](#appconfig-creating-environment-console)
+ [创建 Amazon AppConfig 环境（命令行）](#appconfig-creating-environment-commandline)

## 创建 Amazon AppConfig 环境（控制台）
<a name="appconfig-creating-environment-console"></a>

使用以下过程通过 Amazon Systems Manager 控制台创建 Amazon AppConfig 环境。

**创建环境**

1. 打开 Amazon Systems Manager 控制台，网址为[https://console.aws.amazon.com/systems-manager/appconfig/](https://console.amazonaws.cn/systems-manager/appconfig/)。

1. 在导航窗格中，选择**应用程序**，然后选择应用程序的名称来打开详细信息页面。

1. 选择**环境**选项卡，然后选择**创建环境**。

1. 对于 **Name (名称)**，请输入环境的名称。

1. 对于 **Description (描述)**，请输入有关环境的信息。

1. （可选）在**监控**部分，选择 **IAM 角色**字段，然后选择一个有权对您要监控相关警报的指标调用 `cloudwatch:DescribeAlarms` 的 IAM 角色。

1. 在**CloudWatch 警报**列表中，输入 Amazon 资源名称 (ARN) 一个或多个要监控的指标。 Amazon AppConfig 如果其中一个指标进入`ALARM`状态，则回滚您的配置部署。有关建议的指标的信息，请参阅[监控部署以实现自动回滚](monitoring-deployments.md)。

1. （可选）在**关联扩展**部分中，从列表中选择一个扩展。有关更多信息，请参阅 [了解 Amazon AppConfig 扩展](working-with-appconfig-extensions-about.md)。

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

1. 选择**创建环境**。

Amazon AppConfig 创建环境，然后显示**环境详细信息**页面。继续执行[在中创建配置文件 Amazon AppConfig](appconfig-creating-configuration-profile.md)。

## 创建 Amazon AppConfig 环境（命令行）
<a name="appconfig-creating-environment-commandline"></a>

以下过程介绍如何使用 Amazon CLI （在 Linux 或 Windows 上）或 Amazon Tools for PowerShell 如何创建 Amazon AppConfig 环境。

**分步创建环境**

1. 打开 Amazon CLI.

1. 运行以下命令以创建环境。

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

   ```
   aws appconfig create-environment \
     --application-id {{The_application_ID}} \
     --name {{A_name_for_the_environment}} \
     --description {{A_description_of_the_environment}} \
     --monitors "AlarmArn={{ARN_of_the_Amazon_CloudWatch_alarm}},AlarmArnRole={{ARN_of_the_IAM role_for_Amazon AppConfig_to_monitor_AlarmArn}}" \
     --tags {{User_defined_key_value_pair_metadata_of_the_environment}}
   ```

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

   ```
   aws appconfig create-environment ^
     --application-id {{The_application_ID}} ^
     --name {{A_name_for_the_environment}} ^
     --description {{A_description_of_the_environment}} ^
     --monitors "AlarmArn={{ARN_of_the_Amazon_CloudWatch_alarm}},AlarmArnRole={{ARN_of_the_IAM role_for_Amazon AppConfig_to_monitor_AlarmArn}}" ^
     --tags {{User_defined_key_value_pair_metadata_of_the_environment}}
   ```

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

   ```
   New-APPCEnvironment `
     -Name {{Name_for_the_environment}} `
     -ApplicationId {{The_application_ID}}
     -Description {{Description_of_the_environment}} `
     -Monitors @{"AlarmArn={{ARN_of_the_Amazon_CloudWatch_alarm}},AlarmArnRole={{ARN_of_the_IAM role_for_Amazon AppConfig_to_monitor_AlarmArn}}"} `
     -Tag {{Hashtable_type_user_defined_key_value_pair_metadata_of_the_environment}}
   ```

------

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

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

   ```
   {
      "ApplicationId": "The application ID",
      "Id": "The_environment ID",
      "Name": "Name of the environment",
      "State": "The state of the environment",
      "Description": "Description of the environment",
      
      "Monitors": [ 
         { 
            "AlarmArn": "ARN of the Amazon CloudWatch alarm",
            "AlarmRoleArn": "ARN of the IAM role for AppConfig to monitor AlarmArn"
         }
      ]  
   }
   ```

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

   ```
   {
      "ApplicationId": "The application ID",
      "Id": "The environment ID",
      "Name": "Name of the environment",
      "State": "The state of the environment"
      "Description": "Description of the environment",
      
      "Monitors": [ 
         { 
            "AlarmArn": "ARN of the Amazon CloudWatch alarm",
            "AlarmRoleArn": "ARN of the IAM role for AppConfig to monitor AlarmArn"
         }
      ] 
   }
   ```

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

   ```
   ApplicationId     : The application ID
   ContentLength     : Runtime of the command
   Description       : Description of the environment
   HttpStatusCode    : HTTP Status of the runtime
   Id                : The environment ID
   Monitors          : {ARN of the Amazon CloudWatch alarm, ARN of the IAM role for AppConfig to monitor AlarmArn}
   Name              : Name of the environment
   Response Metadata : Runtime Metadata
   State             : State of the environment
   ```

------

继续执行[在中创建配置文件 Amazon AppConfig](appconfig-creating-configuration-profile.md)。