

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 中為您的應用程式建立環境 AWS AppConfig
<a name="appconfig-creating-environment"></a>

對於每個 AWS AppConfig 應用程式，您可以定義一或多個環境。環境是 AppConfig 目標的邏輯部署群組，例如 `Beta`或 `Production`環境、 AWS Lambda 函數或容器中的應用程式。您也可以定義應用程式子元件的環境，例如 `Web`、 `Mobile`和 `Back-end`。您可以為每個環境設定 Amazon CloudWatch 警示。系統會在組態部署期間監控警示。如果觸發了警示，系統會回復組態。

**開始之前**  
如果您想要讓 AWS AppConfig 復原組態以回應 CloudWatch 警示，則必須設定具有許可的 AWS Identity and Access Management (IAM) 角色，讓 AWS AppConfig 能夠回應 CloudWatch 警示。您可以在下列程序中選擇此角色。如需詳細資訊，請參閱[設定自動轉返的許可](setting-up-appconfig.md#getting-started-with-appconfig-cloudwatch-alarms-permissions)。

**Topics**
+ [建立 AWS AppConfig 環境 （主控台）](#appconfig-creating-environment-console)
+ [建立 AWS AppConfig 環境 （命令列）](#appconfig-creating-environment-commandline)

## 建立 AWS AppConfig 環境 （主控台）
<a name="appconfig-creating-environment-console"></a>

使用下列程序，透過 AWS Systems Manager 主控台建立 AWS AppConfig 環境。

**建立環境**

1. 在 https：//[https://console.aws.amazon.com/systems-manager/appconfig/](https://console.aws.amazon.com/systems-manager/appconfig/) 開啟 AWS Systems Manager 主控台。

1. 在導覽窗格中，選擇**應用程式**，然後選擇應用程式的名稱以開啟詳細資訊頁面。

1. 選擇**環境**索引標籤，然後選擇**建立環境**。

1. 對於 **Name (名稱)**，輸入環境的名稱。

1. 對於 **Description (描述)**，輸入有關環境的資訊。

1. （選用） 在**監控**區段中，選擇 **IAM 角色**欄位，然後選擇具有許可的 IAM 角色，以`cloudwatch:DescribeAlarms`呼叫您要監控警示的指標。

1. 在 **CloudWatch 警示**清單中，輸入要監控的 Amazon Resource Name ARNs) 一或多個指標。如果其中一個指標進入 `ALARM` 狀態， 會 AWS AppConfig 復原您的組態部署。如需建議指標的資訊，請參閱 [監控部署的自動復原](monitoring-deployments.md)

1. （選用） 在**關聯延伸**項目區段中，從清單中選擇延伸項目。如需詳細資訊，請參閱[了解 AWS AppConfig 擴充功能](working-with-appconfig-extensions-about.md)。

1. （選用） 在**標籤**區段中，輸入索引鍵和選用值。您可以為資源指定最多 50 個標籤。

1. 選擇 **Create environment** (建立環境)。

AWS AppConfig 會建立環境，然後顯示**環境詳細資訊**頁面。繼續執行「[在 中建立組態設定檔 AWS AppConfig](appconfig-creating-configuration-profile.md)」。

## 建立 AWS AppConfig 環境 （命令列）
<a name="appconfig-creating-environment-commandline"></a>

下列程序說明如何使用 AWS CLI （在 Linux 或 Windows 上） 或 AWS Tools for PowerShell 來建立 AWS AppConfig 環境。

**逐步建立環境**

1. 開啟 AWS 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_AWS 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_AWS 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_AWS 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
   ```

------

繼續執行「[在 中建立組態設定檔 AWS AppConfig](appconfig-creating-configuration-profile.md)」。