

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

# 更新使用者集區和應用程式用戶端組態
<a name="cognito-user-pool-updating"></a>

當您想要變更使用者集區或應用程式用戶端中的設定時，只要按幾下滑鼠，就可以在 Amazon Cognito 主控台中套用更新。您可以導覽使用者集區設定中的功能型索引標籤，並更新本指南其他部分所述的欄位。

許多組織會以程式設計方式管理資源 AWS CloudFormation、建置在 AWS SDKs或 CDK 上的應用程式，以及其他自動化軟體。當這是您的資源管理模型時，您必須在分階段變更資源時格外小心。

API 操作 [ UpdateUserPool](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UpdateUserPool.html) 和 [ UpdateUserPoolClient](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UpdateUserPoolClient.html) 會更新現有的使用者集區或應用程式用戶端。每個 都隨附 API 參考中的警告：*如果您未提供 屬性的值，Amazon Cognito 會將它設定為預設值。*當您使用一個參數提交更新請求時，Amazon Cognito 會將該參數設定為您選擇的值，並將所有其他參數設定為預設值。這可以重設組態，包括您的屬性結構描述、Lambda 觸發條件，以及您的電子郵件和簡訊組態。

此外，在您建立使用者集區或應用程式用戶端之後，某些設定會鎖定在 中，除非您建立新的資源，否則無法變更這些設定。

**Topics**
+ [您無法變更的設定](#cognito-user-pool-updating-fixed-settings)
+ [SMS 組態](#cognito-user-pool-updating-sms)
+ [使用 AWS SDK AWS CDK或 REST API 更新使用者集區](#cognito-user-pool-updating-api-cli)

## 您無法變更的設定
<a name="cognito-user-pool-updating-fixed-settings"></a>

建立使用者集區之後，您就無法變更某些設定。如果您想要變更以下設定，則必須建立新的使用者集區或應用程式用戶端。

**注意**  
先前，您無法變更使用者集區的名稱。這已變更。您現在可以將新的易記名稱指派給使用者集區。

**使用者集區 ID**  
API 參數名稱：[Id/UserPoolId](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UserPoolType.html#CognitoUserPools-Type-UserPoolType-ID)  
使用者集區 ID，例如 `us-east-1_EXAMPLE`，是由 Amazon Cognito 自動產生且無法變更。

**Amazon Cognito 使用者集區登入選項**  
API 參數名稱：[AliasAttributes](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPool.html#CognitoUserPools-CreateUserPool-request-AliasAttributes) 和 [UsernameAttributes](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPool.html#CognitoUserPools-CreateUserPool-request-UsernameAttributes)  
使用者登入時可以作為使用者名稱傳遞的屬性。當您建立使用者集區時，您可以選擇允許以使用者名稱、電子郵件地址、電話號碼或偏好的使用者名稱進行登入。若要變更使用者集區登入選項，請建立新的使用者集區。

**讓使用者名稱區分大小寫**  
API 參數名稱：[UsernameConfiguration](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPool.html#CognitoUserPools-CreateUserPool-request-UsernameConfiguration)  
當您建立的使用者名稱符合其他使用者名稱 (字母大小寫除外) 時，Amazon Cognito 可以將他們視為同一個使用者或獨一無二的多個使用者。如需詳細資訊，請參閱[使用者集區大小寫區分](user-pool-case-sensitivity.md)。若要變更區分大小寫，請建立新的使用者集區。

**Client secret (用戶端密碼)**  
API 參數名稱：[GenerateSecret](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPoolClient.html#CognitoUserPools-CreateUserPoolClient-request-GenerateSecret)  
若建立應用程式用戶端，您可以產生用戶端密碼，以便只有信任的來源才能向您的使用者集區提出請求。如需詳細資訊，請參閱[使用應用程式用戶端的應用程式特定設定](user-pool-settings-client-apps.md)。若要變更用戶端密碼，請在同一個使用者集區中建立新的應用程式用戶端。

**必要屬性**  
API 參數名稱：[結構描述](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPool.html#CognitoUserPools-CreateUserPool-request-Schema)  
您的使用者註冊時，或您建立使用者時，您的使用者必須提供其值的屬性。如需詳細資訊，請參閱[使用使用者屬性](user-pool-settings-attributes.md)。若要變更所需的屬性，請建立新的使用者集區。

**自訂屬性 （刪除）**  
API 參數名稱：[結構描述](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPool.html#CognitoUserPools-CreateUserPool-request-Schema)  
具有自訂名稱的屬性。您可以變更使用者的自訂屬性值，但無法將自訂屬性從使用者集區中刪除。如需詳細資訊，請參閱[使用使用者屬性](user-pool-settings-attributes.md)。如果達到自訂屬性數目上限，且想要修改清單，請建立一個新的使用者集區。

## SMS 組態
<a name="cognito-user-pool-updating-sms"></a>

在使用者集區中啟用簡訊之後，您就無法停用它們。
+ 如果您選擇在建立使用者集區時設定 SMS 訊息，在完成設定後就無法停用 SMS。
+ 您可以在您建立的使用者集區中啟用簡訊，但之後無法停用簡訊。
+ Amazon Cognito 可以使用 SMS 訊息進行使用者帳戶邀請和復原、屬性驗證和多重要素驗證 (MFA)。啟用 SMS 訊息後，您可以隨時開啟或關閉這些函數的 SMS 訊息。
+ SMS 訊息組態包含您委派給 Amazon Cognito 以使用 Amazon SNS 傳送訊息的 IAM 角色。您可以隨時變更指派的角色。

## 使用 AWS SDK AWS CDK或 REST API 更新使用者集區
<a name="cognito-user-pool-updating-api-cli"></a>

在 Amazon Cognito 主控台中，您可以一次變更一個參數的使用者集區設定。例如，若要新增 Lambda 觸發條件，請選擇**新增 Lambda 觸發**條件，然後選擇函數和觸發條件類型。Amazon Cognito 使用者集區 API 的結構方式是更新使用者集區和應用程式用戶端的操作，需要使用者集區的一組完整參數。不過，主控台會使用其他使用者集區設定，以透明方式自動化此更新操作。

當變更與您要變更的設定無關時，有時您可能會發現變更 AWS 帳戶 可能會導致更新產生錯誤。 AWS WAF例如，已刪除的 Amazon SES 身分或 IAM 許可的變更。如果其中一個目前的參數不再有效，則在修正之前，您無法更新設定。當您遇到此類錯誤時，請檢查錯誤回應並驗證其提及的設定。

[AWS Cloud Development Kit (AWS CDK)](https://aws.amazon.com/cdk)、[Amazon Cognito 使用者集區 REST API](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/Welcome.html) 和 [AWS SDKs](https://aws.amazon.com/developer/tools/) 是 Amazon Cognito 資源自動化和程式設計組態的工具。使用這些工具的請求也必須像 Amazon Cognito 主控台一樣，在請求內文中更新具有完整資源組態的設定。在高階，您必須執行下列程序。

1. 從描述現有資源組態的 操作擷取輸出。

1. 在您的設定變更時修改輸出。

1. 在更新資源的 操作中傳送修改後的組態。

以下程序以 [UpdateUserPool](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UpdateUserPool.html) API 操作更新您的組態。同樣的方法，使用不同的輸入欄位，適用於 [UpdateUserPoolClient](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UpdateUserPoolClient.html)。

**重要**  
如果您未提供現有參數的值，則 Amazon Cognito 會將這些參數設定為預設值。例如，當您有現有 `LambdaConfig` 並提交了 `UpdateUserPool` 搭配空白 `LambdaConfig`，您會刪除所有 Lambda 函數給使用者集區觸發條件的指派。當您希望自動變更您的使用者集區組態時，請相應進行規劃。

1. 以 [ DescribeUserPool](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_DescribeUserPool.html) 擷取您使用者集區的現有狀態。

1. 設定 `DescribeUserPool` 的輸出格式，以符合 `UpdateUserPool` 的[請求參數](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UpdateUserPool.html#API_UpdateUserPool_RequestSyntax)。將下列頂層欄位及其子物件自輸出 JSON 中移除。
   + `Arn`
   + `CreationDate`
   + `CustomDomain`
     + 以 [UpdateUserPoolDomain](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UpdateUserPoolDomain.html) API 操作更新此欄位。
   + `Domain`
     + 以 [UpdateUserPoolDomain](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UpdateUserPoolDomain.html) API 操作更新此欄位。
   + `EmailConfigurationFailure`
   + `EstimatedNumberOfUsers`
   + `Id`
   + `LastModifiedDate`
   + `Name`
   + `SchemaAttributes`
   + `SmsConfigurationFailure`
   + `Status`

1. 確認產生的 JSON 符合 `UpdateUserPool` 的[請求參數](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UpdateUserPool.html#API_UpdateUserPool_RequestSyntax)。

1. 修改您想要在產生的 JSON 中變更的任何參數。

1. 將您修改的 JSON 作為請求輸入來提交 `UpdateUserPool` API 請求。

您也可以在 AWS CLI以 `update-user-pool` 的 `--cli-input-json` 參數來使用此修改後的 `DescribeUserPool` 輸出。

或者，執行下列 AWS CLI 命令，為 接受的輸入欄位產生具有空白值的 JSON`update-user-pool`。然後，您可以使用使用者集區中的現有值填入這些欄位。

```
aws cognito-idp update-user-pool --generate-cli-skeleton --output json
```

執行以下命令，為應用程式用戶端產生相同的 JSON 物件。

```
aws cognito-idp update-user-pool-client --generate-cli-skeleton --output json
```