

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

# Load Balancer (ELB) 堆疊 \| 建立接聽程式規則
<a name="deployment-advanced-load-balancer-elb-stack-create-listener-rule"></a>

為特定接聽程式建立接聽程式規則。Application Load Balancer 接聽程式 æforwardÆ 和 æredirectedÆ 是唯一支援的規則類型

**完整分類：**部署 \| 進階堆疊元件 \| 負載平衡器 (ELB) 堆疊 \| 建立接聽程式規則

## 變更類型詳細資訊
<a name="ct-18weo4vv83ynk-DALc-table"></a>


****  

|  |  | 
| --- |--- |
| 變更類型 ID | ct-18weo4v83ynk | 
| 目前版本 | 1.0 | 
| 預期的執行持續時間 | 60 分鐘 | 
| AWS 核准 | 必要 | 
| 客戶核准 | 非必要 | 
| 執行模式 | 自動化 | 

## 其他資訊
<a name="deployment-advanced-load-balancer-elb-stack-create-listener-rule-info"></a>

### 建立 ELB 接聽程式規則
<a name="ex-load-balancer-create-elb-listener-rule-col"></a>

#### 使用主控台建立 ELB 接聽程式規則
<a name="load-balancer-create-elb-listener-rule-con"></a>

AMS 主控台中此變更類型的螢幕擷取畫面：

![AMS Advanced 主控台、建立 RFC 區段、ct-18weo4v83ynk 的變更類型詳細資訊方塊：建立 ELB 接聽程式規則。](http://docs.aws.amazon.com/zh_tw/managedservices/latest/ctref/images/guiLoadBalancerCreateELBListenerRule.png)


運作方式：

1. 導覽至**建立 RFC** 頁面：在 AMS 主控台的左側導覽窗格中，按一下 **RFCs**以開啟 RFCs清單頁面，然後按一下**建立 RFC**。

1. 在預設的**瀏覽變更類型檢視中選擇熱門的變更類型** (CT)，或在**依類別**選擇檢視中選擇 CT。
   + **依變更類型瀏覽**：您可以在**快速建立**區域中按一下熱門的 CT，以立即開啟**執行 RFC** 頁面。請注意，您無法透過快速建立選擇較舊的 CT 版本。

     若要排序 CTs，請使用**卡片**或**資料表**檢視中的所有**變更類型**區域。在任一檢視中，選取 CT，然後按一下**建立 RFC** 以開啟**執行 RFC** 頁面。如果適用，**建立舊版**選項會顯示在**建立 RFC** 按鈕旁。
   + **依類別選擇**：選取類別、子類別、項目和操作，如果適用，CT 詳細資訊方塊會開啟，其中包含**使用較舊版本建立**的選項。按一下**建立 RFC** 以開啟**執行 RFC** 頁面。

1. 在**執行 RFC** 頁面上，開啟 CT 名稱區域以查看 CT 詳細資訊方塊。需要**主旨** （如果您在**瀏覽變更類型**檢視中選擇 CT，則會為您填寫）。開啟**其他組態**區域以新增 RFC 的相關資訊。

   在**執行組態**區域中，使用可用的下拉式清單或輸入必要參數的值。若要設定選用的執行參數，請開啟**其他組態**區域。

1. 完成後，請按一下**執行**。如果沒有錯誤，**RFC 成功建立**的頁面會顯示已提交的 RFC 詳細資訊，以及初始的**執行輸出**。

1. 開啟**執行參數**區域以查看您提交的組態。重新整理頁面以更新 RFC 執行狀態。或者，取消 RFC 或使用頁面頂端的選項建立 RFC 的副本。

#### 使用 CLI 建立 ELB 接聽程式規則
<a name="load-balancer-create-elb-listener-rule-cli"></a>

運作方式：

1. 使用內嵌建立 （您發出包含所有 RFC 和執行參數的`create-rfc`命令） 或範本建立 （您建立兩個 JSON 檔案，一個用於 RFC 參數，另一個用於執行參數），並使用兩個檔案作為輸入發出`create-rfc`命令。此處說明這兩種方法。

1. 使用傳回的 RFC ID 提交 RFC： `aws amscm submit-rfc --rfc-id {{ID}}`命令。

   監控 RFC： `aws amscm get-rfc --rfc-id {{ID}}`命令。

若要檢查變更類型版本，請使用下列命令：

```
aws amscm list-change-type-version-summaries --filter Attribute=ChangeTypeId,Value={{CT_ID}}
```
**注意**  
您可以將任何`CreateRfc`參數與任何 RFC 搭配使用，無論它們是否為變更類型結構描述的一部分。例如，若要在 RFC 狀態變更時取得通知，請將此行新增至請求的 `--notification "{\"Email\": {\"EmailRecipients\" : [\"email@example.com\"]}}"` RFC 參數部分 （而非執行參數）。如需所有 CreateRfc 參數的清單，請參閱 [AMS 變更管理 API 參考](https://docs.aws.amazon.com/managedservices/latest/ApiReference-cm/API_CreateRfc.html)。

*內嵌建立*：

使用內嵌提供的執行參數發出建立 RFC 命令 （在內嵌提供執行參數時逸出引號），然後提交傳回的 RFC ID。例如，您可以將內容取代為如下內容：

```
aws amscm create-rfc --change-type-id "ct-18weo4vv83ynk" --change-type-version "1.0" --title "Create ALB Listener Rule" --execution-parameters "{\"DocumentName\":\"AWSManagedServices-CreateListenerRule\",\"Parameters\":{\"ListenerArn\":[\"{{LISTENER_ARN}}\"],\"Conditions\":[\"{\\\"{{Field}}\\\":\\\"{{path-pattern}}\\\",\\\"{{PathPatternConfig}}\\\":{\\\"{{Values}}\\\":[\\\"/{{img}}/*\\\"]}}\"],\"RuleType\":[\"{{redirect}}\"],\"Priority\":[\"{{200}}\"],\"TargetGroups\":[\"{{{}}}\"],\"TargetGroupStickinessConfig\":[\"{{\}}"],\"TargetGroupStickinessDuration\":[\"{{\}}"],\"RedirectProtocol\":[\"{{HTTP}}\"],\"RedirectPort\":[\"{{85}}\"],\"RedirectHost\":[\"{{www.example.com}}\"],\"RedirectPath\":[\"/{{new-path}}\"],\"RedirectQuery\":[\"{{page1}}\"],\"RedirectStatusCode\":[\"{{HTTP_301}}\"]},\"Region\":\"{{REGION}}\""}"
```

```
aws amscm create-rfc --change-type-id "ct-18weo4vv83ynk" --change-type-version "1.0" --title "Create ALB Listener Rule" --execution-parameters "{\"DocumentName\":\"AWSManagedServices-CreateListenerRule\",\"Parameters\":{\"ListenerArn\":[\"{{LISTENER_ARN}}\"],\"Conditions\":[\"{\\\"{{Field}}\\\":\\\"{{path-pattern}}\\\",\\\"{{PathPatternConfig}}\\\":{\\\"{{Values}}\\\":[\\\"/{{img}}/*\\\"]}}\"],\"RuleType\":[\"{{forward}}\"],\"Priority\":[\"{{125}}\"],\"TargetGroups\":[\"{\\\"{{TargetGroupArn}}\\\":\\\"{{TARGET_GROUP_ARN}}\\\",\\\"{{Weight}}\\\":\\\"{{20}}\\\"}\"],\"TargetGroupStickinessConfig\":[\"{{Enabled}}\"],\"TargetGroupStickinessDuration\":[\"{{15}}\"],\"RedirectProtocol\":[\"{{\}}"],\"RedirectPort\":[\"{{\}}"],\"RedirectHost\":[\"{{\}}"],\"RedirectPath\":[\"{{\}}"],\"RedirectQuery\":[\"{{\}}"],\"RedirectStatusCode\":[\"{{\}}"]},\"Region\":\"{{REGION}}\"}"
```

*範本建立*：

1. 將此變更類型的執行參數輸出至名為 validateCreateRule.Actions.json.

   ```
   aws amscm get-change-type-version --change-type-id "ct-18weo4vv83ynk" --query "ChangeTypeVersion.ExecutionInputSchema" --output text > validateCreateRule.Actions.json
   ```

1. 修改並儲存執行參數 JSON 檔案。例如，您可以將內容取代為如下內容：

   所有參數範例：

   ```
   {
   "DocumentName": "AWSManagedServices-CreateListenerRule",
   "Region": "{{us-west-2}}",
   "Parameters": {
     "ListenerArn": ["{{LISTENER_ARN}}"],
     "Conditions": ["{\"{{Field}}\":\"{{host-header}}\",\"{{HostHeaderConfig}}\":{\"{{Values}}\":[\"{{example.com}}\"]}}"],
     "RuleType": ["{{forward}}"],
     "Priority": ["{{200}}"],
     "TargetGroups": ["{\"{{TargetGroupArn}}\":\"{{TARGET_GROUP_ARN}}\",\"{{Weight}}\":\"{{100}}\"}"],
     "TargetGroupStickinessConfig": ["{{Enabled}}"],
     "TargetGroupStickinessDuration": ["{{86400}}"],
     "RedirectProtocol": [""],
     "RedirectPort": [""],
     "RedirectHost": [""],
     "RedirectPath": [""],
     "RedirectQuery": [""],
     "RedirectStatusCode": [""],
     "Priority": "{{High}}"
   }
   }
   ```

   ```
   {
   "DocumentName": "AWSManagedServices-CreateListenerRule",
   "Parameters": {
     "ListenerArn": [
       "{{LISTENER_ARN}}"
     ],
     "Conditions": [
       "{\"{{Field}}\":\"{{path-pattern}}\",\"{{PathPatternConfig}}\":{\"{{Values}}\":[\"/{{img}}/*\"]}}"
     ],
     "RuleType": [
       "{{forward}}"
     ],
     "Priority": [
       "{{125}}"
     ],
     "TargetGroups": [
       "{\"{{TargetGroupArn}}\":\"{{TARGET_GROUP_ARN}}\",\"{{Weight}}\":\"{{20}}\"}"
     ],
     "TargetGroupStickinessConfig": [
       "{{Enabled}}"
     ],
     "TargetGroupStickinessDuration": [
       "{{15}}"
     ],
     "RedirectProtocol": [
       ""
     ],
     "RedirectPort": [
       ""
     ],
     "RedirectHost": [
       ""
     ],
     "RedirectPath": [
       ""
     ],
     "RedirectQuery": [
       ""
     ],
     "RedirectStatusCode": [
       ""
     ]
   },
   "Region": "{{REGION}}",
   "Priority": "{{High}}"
   }
   ```

1. 將 JSON 範本輸出至目前資料夾中的檔案；此範例會將其命名為 CreateListenerRuleRfc.json:

   ```
   aws amscm create-rfc --generate-cli-skeleton > CreateListenerRuleRfc.json
   ```

1. 修改並儲存 CreateListenerRuleRfc.json 檔案。例如，您可以將內容取代為如下內容：

   ```
   {
   "ChangeTypeVersion": "{{1.0}}",
   "ChangeTypeId": "ct-18weo4vv83ynk",
   "Title": "{{Create ALB Listener Rule}}"
   }
   ```

1. 建立 RFC，指定執行參數檔案和 validateCreateRule 檔案：

   ```
   aws amscm create-rfc --cli-input-json file://CreateListenerRuleRfc.json  --execution-parameters file://validateCreateRule.json
   ```

   您會在回應中收到新 RFC 的 ID，並使用它來提交和監控 RFC。在您提交之前，RFC 會保持在編輯狀態，不會啟動。

#### 提示
<a name="ex-load-balancer-create-elb-listener-rule-tip"></a>

若要進一步了解 AWS Application Load Balancer，請參閱[什麼是 Application Load Balancer？](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html)

## 執行輸入參數
<a name="deployment-advanced-load-balancer-elb-stack-create-listener-rule-input"></a>

如需執行輸入參數的詳細資訊，請參閱 [變更類型的結構描述 ct-18weo4v83ynk](schemas.md#ct-18weo4vv83ynk-schema-section)。

## 範例：必要參數
<a name="deployment-advanced-load-balancer-elb-stack-create-listener-rule-ex-min"></a>

```
{
  "DocumentName": "AWSManagedServices-CreateListenerRule",
  "Region": "us-east-1",
  "Parameters": {
    "ListenerArn": ["arn:aws:elasticloadbalancing:us-east-1:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2"],
    "Conditions": ["{\"Field\":\"path-pattern\",\"PathPatternConfig\":{\"Values\":[\"/img/*\"]}}"],
    "RuleType": ["forward"],
    "Priority": ["100"]
  }
}
```

## 範例：所有參數
<a name="deployment-advanced-load-balancer-elb-stack-create-listener-rule-ex-max"></a>

```
{
  "DocumentName": "AWSManagedServices-CreateListenerRule",
  "Region": "us-west-2",
  "Parameters": {
    "ListenerArn": ["arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2"],
    "Conditions": ["{\"Field\":\"host-header\",\"HostHeaderConfig\":{\"Values\":[\"example.com\"]}}"],
    "RuleType": ["forward"],
    "Priority": ["200"],
    "TargetGroups": ["{\"TargetGroupArn\":\"arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067\",\"Weight\":\"100\"}"],
    "TargetGroupStickinessConfig": ["Enabled"],
    "TargetGroupStickinessDuration": ["86400"],
    "RedirectProtocol": [""],
    "RedirectPort": [""],
    "RedirectHost": [""],
    "RedirectPath": [""],
    "RedirectQuery": [""],
    "RedirectStatusCode": [""]
  }
}
```