

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

# 教學課程：建立配對規則集
<a name="match-create-ruleset"></a>

在您為配對Amazon GameLift ServersFlexMatch建構器建立配對規則集之前，建議您檢查[規則集語法](match-rules-reference.md)。使用Amazon GameLift Servers主控台或 AWS Command Line Interface (AWS CLI) 建立規則集後，您無法變更規則集。

請注意，您可以在 區域中擁有的規則集數目上限有[服務配額](https://console.aws.amazon.com/servicequotas/home/services/gamelift/quotas/) AWS ，因此最好刪除未使用的規則集。

**Topics**

------
#### [ Console ]

**建立規則集**

1. 在 https：//[https://console.aws.amazon.com/gamelift/](https://console.aws.amazon.com/gamelift/) 開啟 Amazon GameLift Servers主控台。

1. 切換到您要建立規則集 AWS 的區域。在與使用規則的配對組態相同的區域中定義規則集。

1. 在導覽窗格中，選擇 **FlexMatch**、**配對規則集**。

1. 在**配對規則集**頁面上，選擇**建立規則集**。

1. 在**建立配對規則集**頁面上，執行下列動作：

   1. 在**規則集設定**下，針對**名稱**輸入唯一的描述性名稱，可用於在清單或事件和指標資料表中識別它。

   1. 針對**規則集**，以 JSON 輸入您的規則集。如需設計規則集的資訊，請參閱 [設計FlexMatch規則集](match-design-ruleset.md)。您也可以從 使用其中一個範例規則集[FlexMatch 規則集範例](match-examples.md)。

   1. 選擇**驗證**以驗證規則集的語法是否正確。您無法在規則集建立後對其進行編輯，因此最好先進行驗證。

   1. （選用） 在**標籤**下，新增標籤以協助您管理和追蹤 AWS 資源。

1. 選擇**建立**。如果建立成功，您可以搭配配對建構器使用規則集。

------
#### [ AWS CLI ]

**建立規則集**

開啟命令列視窗，並使用命令 [create-matchmaking-rule-set](https://docs.aws.amazon.com/cli/latest/reference/gamelift/create-matchmaking-rule-set.html)。

此範例命令會建立簡單的配對規則集，以設定單一團隊。請務必在與使用它的配對組態相同的 AWS 區域中建立規則集。

```
aws gamelift create-matchmaking-rule-set \
    --name "SampleRuleSet123" \
    --rule-set-body '{"name": "aliens_vs_cowboys", "ruleLanguageVersion": "1.0", "teams": [{"name": "cowboys", "maxPlayers": 8, "minPlayers":  4}]}'
```

如果建立請求成功， 會Amazon GameLift Servers傳回包含您指定設定的 [MatchmakingRuleSet](https://docs.aws.amazon.com/gameliftservers/latest/apireference/API_MatchmakingRuleSet.html) 物件。配對建構器現在可以使用新的規則集。

------<a name="match-delete-ruleset"></a><a name="match-delete-ruleset-cli"></a>

------
#### [ Console ]

**刪除規則集**

1. 在 https：//[https://console.aws.amazon.com/gamelift/](https://console.aws.amazon.com/gamelift/) 開啟 Amazon GameLift Servers主控台。

1. 切換到您在其中建立規則集的區域。

1. 在導覽窗格中，選擇 **FlexMatch**、**配對規則集**。

1. 在**配對規則集**頁面上，選取您要刪除的規則集，然後選擇**刪除**。

1. 在**刪除規則集**對話方塊中，選擇**刪除**以確認刪除。
**注意**  
如果配對組態正在使用規則集， Amazon GameLift Servers會顯示錯誤訊息 (**無法刪除規則集**)。如果發生這種情況，請將配對組態變更為使用不同的規則集，然後再試一次。若要了解哪些配對組態正在使用規則集，請選擇規則集的名稱以檢視其詳細資訊頁面。

------
#### [ AWS CLI ]

**刪除規則集**

開啟命令列視窗，並使用命令 [delete-matchmaking-rule-set](https://docs.aws.amazon.com/cli/latest/reference/gamelift/delete-matchmaking-rule-set.html) 刪除配對規則集。

如果配對組態正在使用規則集， 會Amazon GameLift Servers傳回錯誤訊息。如果發生這種情況，請將配對組態變更為使用不同的規則集，然後再試一次。若要取得哪些配對組態正在使用規則集的清單，請使用 命令 [describe-matchmaking-configurations](https://docs.aws.amazon.com/cli/latest/reference/gamelift/describe-matchmaking-configurations.html) 並指定規則集名稱。

此範例命令會檢查配對規則集的使用情況，然後刪除規則集。

```
aws gamelift describe-matchmaking-rule-sets \
    --rule-set-name "SampleRuleSet123" \
    --limit 10

aws gamelift delete-matchmaking-rule-set \
    --name  "SampleRuleSet123"
```

------