使用 的 Amazon Cognito Identity Provider 範例 AWS CLI - AWS Command Line Interface

本文件 AWS CLI 僅適用於 的第 1 版。如需與 第 2 版相關的文件 AWS CLI,請參閱 第 2 版使用者指南

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

使用 的 Amazon Cognito Identity Provider 範例 AWS CLI

下列程式碼範例說明如何 AWS Command Line Interface 搭配 Amazon Cognito Identity Provider 使用 來執行動作和實作常見案例。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會示範如何呼叫個別服務函數,但您可以在其相關案例中查看內容中的動作。

每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例示範如何使用 add-custom-attributes

AWS CLI

若要新增自訂屬性

此範例會將自訂屬性 CustomAttr1 新增至使用者集區。它是字串類型,至少需要 1 個字元,最多 15 個字元。這不是必要的。

命令:

aws cognito-idp add-custom-attributes --user-pool-id us-west-2_aaaaaaaaa --custom-attributes Name="CustomAttr1",AttributeDataType="String",DeveloperOnlyAttribute=false,Required=false,StringAttributeConstraints="{MinLength=1,MaxLength=15}"

下列程式碼範例示範如何使用 admim-disable-user

AWS CLI

停用使用者

此範例會停用使用者 jane@example.com。

命令:

aws cognito-idp admin-disable-user --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com
  • 如需API詳細資訊,請參閱 命令參考 AdmimDisableUser中的 。 AWS CLI

下列程式碼範例示範如何使用 admim-enable-user

AWS CLI

啟用使用者

此範例會啟用使用者名稱 jane@example.com。

命令:

aws cognito-idp admin-enable-user --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com
  • 如需API詳細資訊,請參閱 命令參考 AdmimEnableUser中的 。 AWS CLI

下列程式碼範例示範如何使用 admin-add-user-to-group

AWS CLI

將使用者新增至群組

此範例會將使用者 Jane 新增至群組 MyGroup。

命令:

aws cognito-idp admin-add-user-to-group --user-pool-id us-west-2_aaaaaaaaa --username Jane --group-name MyGroup

下列程式碼範例示範如何使用 admin-confirm-sign-up

AWS CLI

確認使用者註冊

此範例會確認使用者 jane@example.com。

命令:

aws cognito-idp admin-confirm-sign-up --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com

下列程式碼範例示範如何使用 admin-create-user

AWS CLI

建立使用者

下列admin-create-user範例會建立具有指定設定電子郵件地址和電話號碼的使用者。

aws cognito-idp admin-create-user \ --user-pool-id us-west-2_aaaaaaaaa \ --username diego \ --user-attributes Name=email,Value=diego@example.com Name=phone_number,Value="+15555551212" \ --message-action SUPPRESS

輸出:

{ "User": { "Username": "diego", "Attributes": [ { "Name": "sub", "Value": "7325c1de-b05b-4f84-b321-9adc6e61f4a2" }, { "Name": "phone_number", "Value": "+15555551212" }, { "Name": "email", "Value": "diego@example.com" } ], "UserCreateDate": 1548099495.428, "UserLastModifiedDate": 1548099495.428, "Enabled": true, "UserStatus": "FORCE_CHANGE_PASSWORD" } }
  • 如需API詳細資訊,請參閱 命令參考 AdminCreateUser中的 。 AWS CLI

下列程式碼範例示範如何使用 admin-delete-user-attributes

AWS CLI

若要刪除使用者屬性

此範例會刪除使用者 diego@example.com 的自訂屬性 CustomAttr1。

命令:

aws cognito-idp admin-delete-user-attributes --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --user-attribute-names "custom:CustomAttr1"

下列程式碼範例示範如何使用 admin-delete-user

AWS CLI

若要刪除使用者

此範例會刪除使用者。

命令:

aws cognito-idp admin-delete-user --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com
  • 如需API詳細資訊,請參閱 命令參考 AdminDeleteUser中的 。 AWS CLI

下列程式碼範例示範如何使用 admin-forget-device

AWS CLI

忘記裝置

此範例會忘記使用者名稱為 jane@example.com 的裝置

命令:

aws cognito-idp admin-forget-device --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com --device-key us-west-2_abcd_1234-5678

下列程式碼範例示範如何使用 admin-get-device

AWS CLI

若要取得裝置

此範例取得使用者名稱為 jane@example.com 的裝置

命令:

aws cognito-idp admin-get-device --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com --device-key us-west-2_abcd_1234-5678
  • 如需API詳細資訊,請參閱 命令參考 AdminGetDevice中的 。 AWS CLI

下列程式碼範例示範如何使用 admin-get-user

AWS CLI

若要取得使用者

此範例取得使用者名稱 jane@example.com 的相關資訊。

命令:

aws cognito-idp admin-get-user --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com

輸出:

{ "Username": "4320de44-2322-4620-999b-5e2e1c8df013", "Enabled": true, "UserStatus": "FORCE_CHANGE_PASSWORD", "UserCreateDate": 1548108509.537, "UserAttributes": [ { "Name": "sub", "Value": "4320de44-2322-4620-999b-5e2e1c8df013" }, { "Name": "email_verified", "Value": "true" }, { "Name": "phone_number_verified", "Value": "true" }, { "Name": "phone_number", "Value": "+01115551212" }, { "Name": "email", "Value": "jane@example.com" } ], "UserLastModifiedDate": 1548108509.537 }
  • 如需API詳細資訊,請參閱 命令參考 AdminGetUser中的 。 AWS CLI

下列程式碼範例示範如何使用 admin-initiate-auth

AWS CLI

若要啟動授權

此範例使用使用者名稱 jane@example.com 的 ADMIN_NO_SRP_AUTH 流程啟動授權

用戶端必須啟用伺服器型身分驗證 (ADMIN_NO_SRP_AUTH) API的登入。

使用傳回值中的工作階段資訊來呼叫 admin-respond-to-auth-challenge。

命令:

aws cognito-idp admin-initiate-auth --user-pool-id us-west-2_aaaaaaaaa --client-id 3n4b5urk1ft4fl3mg5e62d9ado --auth-flow ADMIN_NO_SRP_AUTH --auth-parameters USERNAME=jane@example.com,PASSWORD=password

輸出:

{ "ChallengeName": "NEW_PASSWORD_REQUIRED", "Session": "SESSION", "ChallengeParameters": { "USER_ID_FOR_SRP": "84514837-dcbc-4af1-abff-f3c109334894", "requiredAttributes": "[]", "userAttributes": "{\"email_verified\":\"true\",\"phone_number_verified\":\"true\",\"phone_number\":\"+01xxx5550100\",\"email\":\"jane@example.com\"}" } }

下列程式碼範例示範如何使用 admin-list-devices

AWS CLI

列出使用者的裝置

此範例會列出使用者名稱為 jane@example.com 的裝置。

命令:

aws cognito-idp admin-list-devices --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com
  • 如需API詳細資訊,請參閱 命令參考 AdminListDevices中的 。 AWS CLI

下列程式碼範例示範如何使用 admin-list-groups-for-user

AWS CLI

列出使用者的群組

此範例會列出使用者名稱 jane@example.com 的群組。

命令:

aws cognito-idp admin-list-groups-for-user --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com

輸出:

{ "Groups": [ { "Description": "Sample group", "Precedence": 1, "LastModifiedDate": 1548097827.125, "RoleArn": "arn:aws:iam::111111111111:role/SampleRole", "GroupName": "SampleGroup", "UserPoolId": "us-west-2_aaaaaaaaa", "CreationDate": 1548097827.125 } ] }

下列程式碼範例示範如何使用 admin-list-user-auth-events

AWS CLI

列出使用者的授權事件

此範例會列出使用者名稱 diego@example.com 的授權事件。

命令:

aws cognito-idp admin-list-user-auth-events --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com

下列程式碼範例示範如何使用 admin-remove-user-from-group

AWS CLI

從群組中移除使用者

此範例會從 移除 jane@example.com SampleGroup。

命令:

aws cognito-idp admin-remove-user-from-group --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com --group-name SampleGroup

下列程式碼範例示範如何使用 admin-reset-user-password

AWS CLI

重設使用者密碼

此範例會重設 diego@example.com 的密碼。

命令:

aws cognito-idp admin-reset-user-password --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com

下列程式碼範例示範如何使用 admin-set-user-mfa-preference

AWS CLI

設定使用者MFA偏好設定

此範例會設定使用者名稱 diego@example.com 的SMSMFA偏好設定。

命令:

aws cognito-idp admin-set-user-mfa-preference --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --sms-mfa-settings Enabled=false,PreferredMfa=false

下列程式碼範例示範如何使用 admin-set-user-settings

AWS CLI

設定使用者設定

此範例將使用者名稱 diego@example.com 的MFA交付偏好設定設定為 EMAIL。

命令:

aws cognito-idp admin-set-user-settings --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --mfa-options DeliveryMedium=EMAIL

下列程式碼範例示範如何使用 admin-update-auth-event-feedback

AWS CLI

提供授權事件的意見回饋

此範例會將 event-id 識別的授權事件的意見回饋值設定為 Valid。

命令:

aws cognito-idp admin-update-auth-event-feedback --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --event-id c2c2cf89-c0d3-482d-aba6-99d78a5b0bfe --feedback-value Valid

下列程式碼範例示範如何使用 admin-update-device-status

AWS CLI

更新裝置狀態

此範例會將裝置金鑰識別之裝置的裝置記住狀態設定為 not_remembered。

命令:

aws cognito-idp admin-update-device-status --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --device-key xxxx --device-remembered-status not_remembered

下列程式碼範例示範如何使用 admin-update-user-attributes

AWS CLI

更新使用者屬性

此範例會更新使用者 diego@example.com 的自訂使用者屬性 CustomAttr1。

命令:

aws cognito-idp admin-update-user-attributes --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --user-attributes Name="custom:CustomAttr1",Value="Purple"

下列程式碼範例示範如何使用 change-password

AWS CLI

若要變更密碼

此範例會變更密碼。

命令:

aws cognito-idp change-password --previous-password OldPassword --proposed-password NewPassword --access-token ACCESS_TOKEN
  • 如需API詳細資訊,請參閱 命令參考 ChangePassword中的 。 AWS CLI

下列程式碼範例示範如何使用 confirm-forgot-password

AWS CLI

確認忘記的密碼

此範例會確認使用者名稱 diego@example.com 的忘記密碼。

命令:

aws cognito-idp confirm-forgot-password --client-id 3n4b5urk1ft4fl3mg5e62d9ado --username=diego@example.com --password PASSWORD --confirmation-code CONF_CODE

下列程式碼範例示範如何使用 confirm-sign-up

AWS CLI

若要確認註冊

此範例會確認註冊使用者名稱 diego@example.com。

命令:

aws cognito-idp confirm-sign-up --client-id 3n4b5urk1ft4fl3mg5e62d9ado --username=diego@example.com --confirmation-code CONF_CODE
  • 如需API詳細資訊,請參閱 命令參考 ConfirmSignUp中的 。 AWS CLI

下列程式碼範例示範如何使用 create-group

AWS CLI

建立群組

此範例會建立具有描述的群組。

命令:

aws cognito-idp create-group --user-pool-id us-west-2_aaaaaaaaa --group-name MyNewGroup --description "New group."

輸出:

{ "Group": { "GroupName": "MyNewGroup", "UserPoolId": "us-west-2_aaaaaaaaa", "Description": "New group.", "LastModifiedDate": 1548270073.795, "CreationDate": 1548270073.795 } }

建立具有角色和優先順序的群組

此範例會建立具有描述的群組。它還包括角色和優先順序。

命令:

aws cognito-idp create-group --user-pool-id us-west-2_aaaaaaaaa --group-name MyNewGroupWithRole --description "New group with a role." --role-arn arn:aws:iam::111111111111:role/MyNewGroupRole --precedence 2

輸出:

{ "Group": { "GroupName": "MyNewGroupWithRole", "UserPoolId": "us-west-2_aaaaaaaaa", "Description": "New group with a role.", "RoleArn": "arn:aws:iam::111111111111:role/MyNewGroupRole", "Precedence": 2, "LastModifiedDate": 1548270211.761, "CreationDate": 1548270211.761 } }
  • 如需API詳細資訊,請參閱 命令參考 CreateGroup中的 。 AWS CLI

下列程式碼範例示範如何使用 create-user-import-job

AWS CLI

建立使用者匯入任務

此範例會建立名為 的使用者匯入任務 MyImportJob。

如需匯入使用者的詳細資訊,請參閱從CSV檔案將使用者匯入使用者集區。

命令:

aws cognito-idp create-user-import-job --user-pool-id us-west-2_aaaaaaaaa --job-name MyImportJob --cloud-watch-logs-role-arn arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole

輸出:

{ "UserImportJob": { "JobName": "MyImportJob", "JobId": "import-qQ0DCt2fRh", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED_URL", "CreationDate": 1548271795.471, "Status": "Created", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 0 } }

使用預先簽署的 上傳具有 curl 的 .csv 檔案URL:

命令:

curl -v -T "PATH_TO_CSV_FILE" -H "x-amz-server-side-encryption:aws:kms" "PRE_SIGNED_URL"

下列程式碼範例示範如何使用 create-user-pool-client

AWS CLI

若要建立使用者集區用戶端

此範例會建立新的使用者集區用戶端,其中包含兩個明確授權流程:USER_PASSWORD_AUTH 和 ADMIN_NO_SRP_AUTH。

命令:

aws cognito-idp create-user-pool-client --user-pool-id us-west-2_aaaaaaaaa --client-name MyNewClient --no-generate-secret --explicit-auth-flows "USER_PASSWORD_AUTH" "ADMIN_NO_SRP_AUTH"

輸出:

{ "UserPoolClient": { "UserPoolId": "us-west-2_aaaaaaaaa", "ClientName": "MyNewClient", "ClientId": "6p3bs000no6a4ue1idruvd05ad", "LastModifiedDate": 1548697449.497, "CreationDate": 1548697449.497, "RefreshTokenValidity": 30, "ExplicitAuthFlows": [ "USER_PASSWORD_AUTH", "ADMIN_NO_SRP_AUTH" ], "AllowedOAuthFlowsUserPoolClient": false } }

下列程式碼範例示範如何使用 create-user-pool-domain

AWS CLI

若要建立使用者集區網域

此範例會建立新的使用者集區網域。 具有兩個明確授權流程:USER_PASSWORD_AUTH 和 ADMIN_NO_SRP_AUTH。

命令:

aws cognito-idp create-user-pool-domain --user-pool-id us-west-2_aaaaaaaaa --domain my-new-domain

下列程式碼範例示範如何使用 create-user-pool

AWS CLI

建立最低限度設定的使用者集區

此範例 MyUserPool 會使用預設值建立名為 的使用者集區。沒有必要的屬性,也沒有應用程式用戶端。MFA 和進階安全性已停用。

命令:

aws cognito-idp create-user-pool --pool-name MyUserPool

輸出:

{ "UserPool": { "SchemaAttributes": [ { "Name": "sub", "StringAttributeConstraints": { "MinLength": "1", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": true, "AttributeDataType": "String", "Mutable": false }, { "Name": "name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "given_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "family_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "middle_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "nickname", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "preferred_username", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "profile", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "picture", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "website", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "email", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Required": false, "Name": "email_verified", "Mutable": true }, { "Name": "gender", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "birthdate", "StringAttributeConstraints": { "MinLength": "10", "MaxLength": "10" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "zoneinfo", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "locale", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "phone_number", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Required": false, "Name": "phone_number_verified", "Mutable": true }, { "Name": "address", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "updated_at", "NumberAttributeConstraints": { "MinValue": "0" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "Number", "Mutable": true } ], "MfaConfiguration": "OFF", "Name": "MyUserPool", "LastModifiedDate": 1547833345.777, "AdminCreateUserConfig": { "UnusedAccountValidityDays": 7, "AllowAdminCreateUserOnly": false }, "EmailConfiguration": {}, "Policies": { "PasswordPolicy": { "RequireLowercase": true, "RequireSymbols": true, "RequireNumbers": true, "MinimumLength": 8, "RequireUppercase": true } }, "CreationDate": 1547833345.777, "EstimatedNumberOfUsers": 0, "Id": "us-west-2_aaaaaaaaa", "LambdaConfig": {} } }

用兩個必要屬性建立新的使用者集區

此範例會建立使用者集區 MyUserPool。集區設定為接受電子郵件作為使用者名稱屬性。它也會使用 Amazon Simple Email Service,將電子郵件來源地址設定為經過驗證的地址。

命令:

aws cognito-idp create-user-pool --pool-name MyUserPool --username-attributes "email" --email-configuration=SourceArn="arn:aws:ses:us-east-1:111111111111:identity/jane@example.com",ReplyToEmailAddress="jane@example.com"

輸出:

{ "UserPool": { "SchemaAttributes": [ { "Name": "sub", "StringAttributeConstraints": { "MinLength": "1", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": true, "AttributeDataType": "String", "Mutable": false }, { "Name": "name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "given_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "family_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "middle_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "nickname", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "preferred_username", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "profile", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "picture", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "website", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "email", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Required": false, "Name": "email_verified", "Mutable": true }, { "Name": "gender", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "birthdate", "StringAttributeConstraints": { "MinLength": "10", "MaxLength": "10" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "zoneinfo", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "locale", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "phone_number", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Required": false, "Name": "phone_number_verified", "Mutable": true }, { "Name": "address", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "updated_at", "NumberAttributeConstraints": { "MinValue": "0" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "Number", "Mutable": true } ], "MfaConfiguration": "OFF", "Name": "MyUserPool", "LastModifiedDate": 1547837788.189, "AdminCreateUserConfig": { "UnusedAccountValidityDays": 7, "AllowAdminCreateUserOnly": false }, "EmailConfiguration": { "ReplyToEmailAddress": "jane@example.com", "SourceArn": "arn:aws:ses:us-east-1:111111111111:identity/jane@example.com" }, "Policies": { "PasswordPolicy": { "RequireLowercase": true, "RequireSymbols": true, "RequireNumbers": true, "MinimumLength": 8, "RequireUppercase": true } }, "UsernameAttributes": [ "email" ], "CreationDate": 1547837788.189, "EstimatedNumberOfUsers": 0, "Id": "us-west-2_aaaaaaaaa", "LambdaConfig": {} } }
  • 如需API詳細資訊,請參閱 命令參考 CreateUserPool中的 。 AWS CLI

下列程式碼範例示範如何使用 delete-group

AWS CLI

若要刪除群組

此範例會刪除群組。

命令:

aws cognito-idp delete-group --user-pool-id us-west-2_aaaaaaaaa --group-name MyGroupName
  • 如需API詳細資訊,請參閱 命令參考 DeleteGroup中的 。 AWS CLI

下列程式碼範例示範如何使用 delete-identity-provider

AWS CLI

若要刪除身分提供者

此範例會刪除身分提供者。

命令:

aws cognito-idp delete-identity-provider --user-pool-id us-west-2_aaaaaaaaa --provider-name Facebook

下列程式碼範例示範如何使用 delete-resource-server

AWS CLI

若要刪除資源伺服器

此範例會刪除名為 weather.example.com 的資源伺服器。

命令:

aws cognito-idp delete-resource-server --user-pool-id us-west-2_aaaaaaaaa --identifier weather.example.com

下列程式碼範例示範如何使用 delete-user-attributes

AWS CLI

刪除使用者屬性

此範例會刪除使用者屬性 "FAVORITE_ANIMAL"。

命令:

aws cognito-idp delete-user-attributes --access-token ACCESS_TOKEN --user-attribute-names "FAVORITE_ANIMAL"

下列程式碼範例示範如何使用 delete-user-pool-client

AWS CLI

若要刪除使用者集區用戶端

此範例會刪除使用者集區用戶端。

命令:

aws cognito-idp delete-user-pool-client --user-pool-id us-west-2_aaaaaaaaa --client-id 38fjsnc484p94kpqsnet7mpld0

下列程式碼範例示範如何使用 delete-user-pool-domain

AWS CLI

若要刪除使用者集區網域

下列delete-user-pool-domain範例會刪除名為 的使用者集區網域 my-domain

aws cognito-idp delete-user-pool-domain \ --user-pool-id us-west-2_aaaaaaaaa \ --domain my-domain

下列程式碼範例示範如何使用 delete-user-pool

AWS CLI

若要刪除使用者集區

此範例使用使用者集區 ID us-west-2_aaaaaaaaaa 刪除使用者集區。

命令:

aws cognito-idp delete-user-pool --user-pool-id us-west-2_aaaaaaaaa
  • 如需API詳細資訊,請參閱 命令參考 DeleteUserPool中的 。 AWS CLI

下列程式碼範例示範如何使用 delete-user

AWS CLI

若要刪除使用者

此範例會刪除使用者。

命令:

aws cognito-idp delete-user --access-token ACCESS_TOKEN
  • 如需API詳細資訊,請參閱 命令參考 DeleteUser中的 。 AWS CLI

下列程式碼範例示範如何使用 describe-identity-provider

AWS CLI

描述身分提供者

此範例描述名為 Facebook 的身分提供者。

命令:

aws cognito-idp describe-identity-provider --user-pool-id us-west-2_aaaaaaaaa --provider-name Facebook

輸出:

{ "IdentityProvider": { "UserPoolId": "us-west-2_aaaaaaaaa", "ProviderName": "Facebook", "ProviderType": "Facebook", "ProviderDetails": { "attributes_url": "https://graph.facebook.com/me?fields=", "attributes_url_add_attributes": "true", "authorize_scopes": myscope", "authorize_url": "https://www.facebook.com/v2.9/dialog/oauth", "client_id": "11111", "client_secret": "11111", "token_request_method": "GET", "token_url": "https://graph.facebook.com/v2.9/oauth/access_token" }, "AttributeMapping": { "username": "id" }, "IdpIdentifiers": [], "LastModifiedDate": 1548105901.736, "CreationDate": 1548105901.736 } }

下列程式碼範例示範如何使用 describe-resource-server

AWS CLI

描述資源伺服器

此範例說明 資源伺服器 weather.example.com。

命令:

aws cognito-idp describe-resource-server --user-pool-id us-west-2_aaaaaaaaa --identifier weather.example.com

輸出:

{ "ResourceServer": { "UserPoolId": "us-west-2_aaaaaaaaa", "Identifier": "weather.example.com", "Name": "Weather", "Scopes": [ { "ScopeName": "weather.update", "ScopeDescription": "Update weather forecast" }, { "ScopeName": "weather.read", "ScopeDescription": "Read weather forecasts" }, { "ScopeName": "weather.delete", "ScopeDescription": "Delete a weather forecast" } ] } }

下列程式碼範例示範如何使用 describe-risk-configuration

AWS CLI

描述風險組態

此範例說明與 pool us-west-2_aaaaaaaaaa 相關聯的風險組態。

命令:

aws cognito-idp describe-risk-configuration --user-pool-id us-west-2_aaaaaaaaa

輸出:

{ "RiskConfiguration": { "UserPoolId": "us-west-2_aaaaaaaaa", "CompromisedCredentialsRiskConfiguration": { "EventFilter": [ "SIGN_IN", "SIGN_UP", "PASSWORD_CHANGE" ], "Actions": { "EventAction": "BLOCK" } }, "AccountTakeoverRiskConfiguration": { "NotifyConfiguration": { "From": "diego@example.com", "ReplyTo": "diego@example.com", "SourceArn": "arn:aws:ses:us-east-1:111111111111:identity/diego@example.com", "BlockEmail": { "Subject": "Blocked sign-in attempt", "HtmlBody": "<!DOCTYPE html>\n<html>\n<head>\n\t<title>HTML email context</title>\n\t<meta charset=\"utf-8\">\n</head>\n<body>\n<pre>We blocked an unrecognized sign-in to your account with this information:\n<ul>\n<li>Time: {login-time}</li>\n<li>Device: {device-name}</li>\n<li>Location: {city}, {country}</li>\n</ul>\nIf this sign-in was not by you, you should change your password and notify us by clicking on <a href={one-click-link-invalid}>this link</a>\nIf this sign-in was by you, you can follow <a href={one-click-link-valid}>this link</a> to let us know</pre>\n</body>\n</html>", "TextBody": "We blocked an unrecognized sign-in to your account with this information:\nTime: {login-time}\nDevice: {device-name}\nLocation: {city}, {country}\nIf this sign-in was not by you, you should change your password and notify us by clicking on {one-click-link-invalid}\nIf this sign-in was by you, you can follow {one-click-link-valid} to let us know" }, "NoActionEmail": { "Subject": "New sign-in attempt", "HtmlBody": "<!DOCTYPE html>\n<html>\n<head>\n\t<title>HTML email context</title>\n\t<meta charset=\"utf-8\">\n</head>\n<body>\n<pre>We observed an unrecognized sign-in to your account with this information:\n<ul>\n<li>Time: {login-time}</li>\n<li>Device: {device-name}</li>\n<li>Location: {city}, {country}</li>\n</ul>\nIf this sign-in was not by you, you should change your password and notify us by clicking on <a href={one-click-link-invalid}>this link</a>\nIf this sign-in was by you, you can follow <a href={one-click-link-valid}>this link</a> to let us know</pre>\n</body>\n</html>", "TextBody": "We observed an unrecognized sign-in to your account with this information:\nTime: {login-time}\nDevice: {device-name}\nLocation: {city}, {country}\nIf this sign-in was not by you, you should change your password and notify us by clicking on {one-click-link-invalid}\nIf this sign-in was by you, you can follow {one-click-link-valid} to let us know" }, "MfaEmail": { "Subject": "New sign-in attempt", "HtmlBody": "<!DOCTYPE html>\n<html>\n<head>\n\t<title>HTML email context</title>\n\t<meta charset=\"utf-8\">\n</head>\n<body>\n<pre>We required you to use multi-factor authentication for the following sign-in attempt:\n<ul>\n<li>Time: {login-time}</li>\n<li>Device: {device-name}</li>\n<li>Location: {city}, {country}</li>\n</ul>\nIf this sign-in was not by you, you should change your password and notify us by clicking on <a href={one-click-link-invalid}>this link</a>\nIf this sign-in was by you, you can follow <a href={one-click-link-valid}>this link</a> to let us know</pre>\n</body>\n</html>", "TextBody": "We required you to use multi-factor authentication for the following sign-in attempt:\nTime: {login-time}\nDevice: {device-name}\nLocation: {city}, {country}\nIf this sign-in was not by you, you should change your password and notify us by clicking on {one-click-link-invalid}\nIf this sign-in was by you, you can follow {one-click-link-valid} to let us know" } }, "Actions": { "LowAction": { "Notify": true, "EventAction": "NO_ACTION" }, "MediumAction": { "Notify": true, "EventAction": "MFA_IF_CONFIGURED" }, "HighAction": { "Notify": true, "EventAction": "MFA_IF_CONFIGURED" } } } } }

下列程式碼範例示範如何使用 describe-user-import-job

AWS CLI

描述使用者匯入任務

此範例說明使用者輸入任務。

如需匯入使用者的詳細資訊,請參閱從CSV檔案將使用者匯入使用者集區。

命令:

aws cognito-idp describe-user-import-job --user-pool-id us-west-2_aaaaaaaaa --job-id import-TZqNQvDRnW

輸出:

{ "UserImportJob": { "JobName": "import-Test1", "JobId": "import-TZqNQvDRnW", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED URL", "CreationDate": 1548271708.512, "Status": "Created", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 0 } }

下列程式碼範例示範如何使用 describe-user-pool-client

AWS CLI

描述使用者集區用戶端

此範例說明使用者集區用戶端。

命令:

aws cognito-idp describe-user-pool-client --user-pool-id us-west-2_aaaaaaaaa --client-id 38fjsnc484p94kpqsnet7mpld0

輸出:

{ "UserPoolClient": { "UserPoolId": "us-west-2_aaaaaaaaa", "ClientName": "MyApp", "ClientId": "38fjsnc484p94kpqsnet7mpld0", "ClientSecret": "CLIENT_SECRET", "LastModifiedDate": 1548108676.163, "CreationDate": 1548108676.163, "RefreshTokenValidity": 30, "ReadAttributes": [ "address", "birthdate", "custom:CustomAttr1", "custom:CustomAttr2", "email", "email_verified", "family_name", "gender", "given_name", "locale", "middle_name", "name", "nickname", "phone_number", "phone_number_verified", "picture", "preferred_username", "profile", "updated_at", "website", "zoneinfo" ], "WriteAttributes": [ "address", "birthdate", "custom:CustomAttr1", "custom:CustomAttr2", "email", "family_name", "gender", "given_name", "locale", "middle_name", "name", "nickname", "phone_number", "picture", "preferred_username", "profile", "updated_at", "website", "zoneinfo" ], "ExplicitAuthFlows": [ "ADMIN_NO_SRP_AUTH", "USER_PASSWORD_AUTH" ], "AllowedOAuthFlowsUserPoolClient": false } }

下列程式碼範例示範如何使用 describe-user-pool-domain

AWS CLI

描述使用者集區用戶端

此範例描述名為 my-domain 的使用者集區網域。

命令:

aws cognito-idp describe-user-pool-domain --domain my-domain

輸出:

{ "DomainDescription": { "UserPoolId": "us-west-2_aaaaaaaaa", "AWSAccountId": "111111111111", "Domain": "my-domain", "S3Bucket": "aws-cognito-prod-pdx-assets", "CloudFrontDistribution": "aaaaaaaaaaaaa.cloudfront.net", "Version": "20190128175402", "Status": "ACTIVE", "CustomDomainConfig": {} } }

下列程式碼範例示範如何使用 describe-user-pool

AWS CLI

描述使用者集區

此範例說明使用者集區 ID us-west-2_aaaaaaaaaaa。

命令:

aws cognito-idp describe-user-pool --user-pool-id us-west-2_aaaaaaaaa

輸出:

{ "UserPool": { "SmsVerificationMessage": "Your verification code is {####}. ", "SchemaAttributes": [ { "Name": "sub", "StringAttributeConstraints": { "MinLength": "1", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": true, "AttributeDataType": "String", "Mutable": false }, { "Name": "name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "given_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "family_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "middle_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "nickname", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "preferred_username", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "profile", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "picture", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "website", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "email", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": true, "AttributeDataType": "String", "Mutable": true }, { "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Required": false, "Name": "email_verified", "Mutable": true }, { "Name": "gender", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "birthdate", "StringAttributeConstraints": { "MinLength": "10", "MaxLength": "10" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "zoneinfo", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "locale", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "phone_number", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Required": false, "Name": "phone_number_verified", "Mutable": true }, { "Name": "address", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "updated_at", "NumberAttributeConstraints": { "MinValue": "0" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "Number", "Mutable": true } ], "EmailVerificationSubject": "Your verification code", "MfaConfiguration": "OFF", "Name": "MyUserPool", "EmailVerificationMessage": "Your verification code is {####}. ", "SmsAuthenticationMessage": "Your authentication code is {####}. ", "LastModifiedDate": 1547763720.822, "AdminCreateUserConfig": { "InviteMessageTemplate": { "EmailMessage": "Your username is {username} and temporary password is {####}. ", "EmailSubject": "Your temporary password", "SMSMessage": "Your username is {username} and temporary password is {####}. " }, "UnusedAccountValidityDays": 7, "AllowAdminCreateUserOnly": false }, "EmailConfiguration": { "ReplyToEmailAddress": "myemail@mydomain.com" "SourceArn": "arn:aws:ses:us-east-1:000000000000:identity/myemail@mydomain.com" }, "AutoVerifiedAttributes": [ "email" ], "Policies": { "PasswordPolicy": { "RequireLowercase": true, "RequireSymbols": true, "RequireNumbers": true, "MinimumLength": 8, "RequireUppercase": true } }, "UserPoolTags": {}, "UsernameAttributes": [ "email" ], "CreationDate": 1547763720.822, "EstimatedNumberOfUsers": 1, "Id": "us-west-2_aaaaaaaaa", "LambdaConfig": {} } }
  • 如需API詳細資訊,請參閱 命令參考 DescribeUserPool中的 。 AWS CLI

下列程式碼範例示範如何使用 forget-device

AWS CLI

忘記裝置

此範例會忘記裝置。

命令:

aws cognito-idp forget-device --device-key us-west-2_abcd_1234-5678
  • 如需API詳細資訊,請參閱 命令參考 ForgetDevice中的 。 AWS CLI

下列程式碼範例示範如何使用 forgot-password

AWS CLI

強制變更密碼

下列forgot-password範例會傳送訊息至 jane@example.com 以變更其密碼。

aws cognito-idp forgot-password --client-id 38fjsnc484p94kpqsnet7mpld0 --username jane@example.com

輸出:

{ "CodeDeliveryDetails": { "Destination": "j***@e***.com", "DeliveryMedium": "EMAIL", "AttributeName": "email" } }
  • 如需API詳細資訊,請參閱 命令參考 ForgotPassword中的 。 AWS CLI

下列程式碼範例示範如何使用 get-csv-header

AWS CLI

若要建立 csv 標頭

此範例會建立 csv 標頭。

如需匯入使用者的詳細資訊,請參閱從CSV檔案將使用者匯入使用者集區。

命令:

aws cognito-idp get-csv-header --user-pool-id us-west-2_aaaaaaaaa

輸出:

{ "UserPoolId": "us-west-2_aaaaaaaaa", "CSVHeader": [ "name", "given_name", "family_name", "middle_name", "nickname", "preferred_username", "profile", "picture", "website", "email", "email_verified", "gender", "birthdate", "zoneinfo", "locale", "phone_number", "phone_number_verified", "address", "updated_at", "cognito:mfa_enabled", "cognito:username" ] }

... 從CSV檔案將使用者匯入使用者集區: https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-using-import-tool.html

  • 如需API詳細資訊,請參閱 命令參考 GetCsvHeader中的 。 AWS CLI

下列程式碼範例示範如何使用 get-group

AWS CLI

取得群組的相關資訊

此範例會取得名為 的群組相關資訊 MyGroup。

命令:

aws cognito-idp get-group --user-pool-id us-west-2_aaaaaaaaa --group-name MyGroup

輸出:

{ "Group": { "GroupName": "MyGroup", "UserPoolId": "us-west-2_aaaaaaaaa", "Description": "A sample group.", "LastModifiedDate": 1548270073.795, "CreationDate": 1548270073.795 } }
  • 如需API詳細資訊,請參閱 命令參考 GetGroup中的 。 AWS CLI

下列程式碼範例示範如何使用 get-signing-certificate

AWS CLI

若要取得簽署憑證

此範例會取得使用者集區的簽署憑證。

命令:

aws cognito-idp get-signing-certificate --user-pool-id us-west-2_aaaaaaaaa

輸出:

{ "Certificate": "CERTIFICATE_DATA" }

下列程式碼範例示範如何使用 get-ui-customization

AWS CLI

若要取得 UI 自訂資訊

此範例會取得使用者集區的 UI 自訂資訊。

命令:

aws cognito-idp get-ui-customization --user-pool-id us-west-2_aaaaaaaaa

輸出:

{ "UICustomization": { "UserPoolId": "us-west-2_aaaaaaaaa", "ClientId": "ALL", "ImageUrl": "https://aaaaaaaaaaaaa.cloudfront.net/us-west-2_aaaaaaaaa/ALL/20190128231240/assets/images/image.jpg", "CSS": ".logo-customizable {\n\tmax-width: 60%;\n\tmax-height: 30%;\n}\n.banner-customizable {\n\tpadding: 25px 0px 25px 10px;\n\tbackground-color: lightgray;\n}\n.label-customizable {\n\tfont-weight: 300;\n}\n.textDescription-customizable {\n\tpadding-top: 10px;\n\tpadding-bottom: 10px;\n\tdisplay: block;\n\tfont-size: 16px;\n}\n.idpDescription-customizable {\n\tpadding-top: 10px;\n\tpadding-bottom: 10px;\n\tdisplay: block;\n\tfont-size: 16px;\n}\n.legalText-customizable {\n\tcolor: #747474;\n\tfont-size: 11px;\n}\n.submitButton-customizable {\n\tfont-size: 14px;\n\tfont-weight: bold;\n\tmargin: 20px 0px 10px 0px;\n\theight: 40px;\n\twidth: 100%;\n\tcolor: #fff;\n\tbackground-color: #337ab7;\n}\n.submitButton-customizable:hover {\n\tcolor: #fff;\n\tbackground-color: #286090;\n}\n.errorMessage-customizable {\n\tpadding: 5px;\n\tfont-size: 14px;\n\twidth: 100%;\n\tbackground: #F5F5F5;\n\tborder: 2px solid #D64958;\n\tcolor: #D64958;\n}\n.inputField-customizable {\n\twidth: 100%;\n\theight: 34px;\n\tcolor: #555;\n\tbackground-color: #fff;\n\tborder: 1px solid #ccc;\n}\n.inputField-customizable:focus {\n\tborder-color: #66afe9;\n\toutline: 0;\n}\n.idpButton-customizable {\n\theight: 40px;\n\twidth: 100%;\n\ttext-align: center;\n\tmargin-bottom: 15px;\n\tcolor: #fff;\n\tbackground-color: #5bc0de;\n\tborder-color: #46b8da;\n}\n.idpButton-customizable:hover {\n\tcolor: #fff;\n\tbackground-color: #31b0d5;\n}\n.socialButton-customizable {\n\theight: 40px;\n\ttext-align: left;\n\twidth: 100%;\n\tmargin-bottom: 15px;\n}\n.redirect-customizable {\n\ttext-align: center;\n}\n.passwordCheck-notValid-customizable {\n\tcolor: #DF3312;\n}\n.passwordCheck-valid-customizable {\n\tcolor: #19BF00;\n}\n.background-customizable {\n\tbackground-color: #faf;\n}\n", "CSSVersion": "20190128231240" } }

下列程式碼範例示範如何使用 list-user-import-jobs

AWS CLI

列出使用者匯入任務

此範例會列出使用者匯入任務。

如需匯入使用者的詳細資訊,請參閱從CSV檔案將使用者匯入使用者集區。

命令:

aws cognito-idp list-user-import-jobs --user-pool-id us-west-2_aaaaaaaaa --max-results 20

輸出:

{ "UserImportJobs": [ { "JobName": "Test2", "JobId": "import-d0OnwGA3mV", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED_URL", "CreationDate": 1548272793.069, "Status": "Created", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 0 }, { "JobName": "Test1", "JobId": "import-qQ0DCt2fRh", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED_URL", "CreationDate": 1548271795.471, "Status": "Created", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 0 }, { "JobName": "import-Test1", "JobId": "import-TZqNQvDRnW", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED_URL", "CreationDate": 1548271708.512, "StartDate": 1548277247.962, "CompletionDate": 1548277248.912, "Status": "Failed", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 1, "CompletionMessage": "Too many users have failed or been skipped during the import." } ] }

下列程式碼範例示範如何使用 list-user-pools

AWS CLI

若要列出使用者集區

此範例會列出多達 20 個使用者集區。

命令:

aws cognito-idp list-user-pools --max-results 20

輸出:

{ "UserPools": [ { "CreationDate": 1547763720.822, "LastModifiedDate": 1547763720.822, "LambdaConfig": {}, "Id": "us-west-2_aaaaaaaaa", "Name": "MyUserPool" } ] }
  • 如需API詳細資訊,請參閱 命令參考 ListUserPools中的 。 AWS CLI

下列程式碼範例示範如何使用 list-users-in-group

AWS CLI

列出群組中的使用者

此範例列出群組 中的使用者 MyGroup。

命令:

aws cognito-idp list-users-in-group --user-pool-id us-west-2_aaaaaaaaa --group-name MyGroup

輸出:

{ "Users": [ { "Username": "acf10624-80bb-401a-ac61-607bee2110ec", "Attributes": [ { "Name": "sub", "Value": "acf10624-80bb-401a-ac61-607bee2110ec" }, { "Name": "custom:CustomAttr1", "Value": "New Value!" }, { "Name": "email", "Value": "jane@example.com" } ], "UserCreateDate": 1548102770.284, "UserLastModifiedDate": 1548103204.893, "Enabled": true, "UserStatus": "CONFIRMED" }, { "Username": "22704aa3-fc10-479a-97eb-2af5806bd327", "Attributes": [ { "Name": "sub", "Value": "22704aa3-fc10-479a-97eb-2af5806bd327" }, { "Name": "email_verified", "Value": "true" }, { "Name": "email", "Value": "diego@example.com" } ], "UserCreateDate": 1548089817.683, "UserLastModifiedDate": 1548089817.683, "Enabled": true, "UserStatus": "FORCE_CHANGE_PASSWORD" } ] }
  • 如需API詳細資訊,請參閱 命令參考 ListUsersInGroup中的 。 AWS CLI

下列程式碼範例示範如何使用 list-users

AWS CLI

若要列出使用者

此範例最多可列出 20 位使用者。

命令:

aws cognito-idp list-users --user-pool-id us-west-2_aaaaaaaaa --limit 20

輸出:

{ "Users": [ { "Username": "22704aa3-fc10-479a-97eb-2af5806bd327", "Enabled": true, "UserStatus": "FORCE_CHANGE_PASSWORD", "UserCreateDate": 1548089817.683, "UserLastModifiedDate": 1548089817.683, "Attributes": [ { "Name": "sub", "Value": "22704aa3-fc10-479a-97eb-2af5806bd327" }, { "Name": "email_verified", "Value": "true" }, { "Name": "email", "Value": "mary@example.com" } ] } ] }
  • 如需API詳細資訊,請參閱 命令參考 ListUsers中的 。 AWS CLI

下列程式碼範例示範如何使用 resend-confirmation-code

AWS CLI

若要重新傳送確認碼

下列 resend-confirmation-code 範例會傳送確認碼給使用者 jane

aws cognito-idp resend-confirmation-code \ --client-id 12a3b456c7de890f11g123hijk \ --username jane

輸出:

{ "CodeDeliveryDetails": { "Destination": "j***@e***.com", "DeliveryMedium": "EMAIL", "AttributeName": "email" } }

如需詳細資訊,請參閱《Amazon Cognito 開發人員指南》中的註冊及確認使用者帳戶

下列程式碼範例示範如何使用 respond-to-auth-challenge

AWS CLI

若要回應身分驗證挑戰

此範例回應使用初始化身份驗證啟動的授權挑戰。這是對 NEW_PASSWORD_REQUIRED 挑戰的回應。它為使用者 jane@example.com 設定密碼。

命令:

aws cognito-idp respond-to-auth-challenge --client-id 3n4b5urk1ft4fl3mg5e62d9ado --challenge-name NEW_PASSWORD_REQUIRED --challenge-responses USERNAME=jane@example.com,NEW_PASSWORD="password" --session "SESSION_TOKEN"

輸出:

{ "ChallengeParameters": {}, "AuthenticationResult": { "AccessToken": "ACCESS_TOKEN", "ExpiresIn": 3600, "TokenType": "Bearer", "RefreshToken": "REFRESH_TOKEN", "IdToken": "ID_TOKEN", "NewDeviceMetadata": { "DeviceKey": "us-west-2_fec070d2-fa88-424a-8ec8-b26d7198eb23", "DeviceGroupKey": "-wt2ha1Zd" } } }

下列程式碼範例示範如何使用 set-risk-configuration

AWS CLI

設定風險組態

此範例會設定使用者集區的風險組態。它將註冊事件動作設定為 NO_ACTION。

命令:

aws cognito-idp set-risk-configuration --user-pool-id us-west-2_aaaaaaaaa --compromised-credentials-risk-configuration EventFilter=SIGN_UP,Actions={EventAction=NO_ACTION}

輸出:

{ "RiskConfiguration": { "UserPoolId": "us-west-2_aaaaaaaaa", "CompromisedCredentialsRiskConfiguration": { "EventFilter": [ "SIGN_UP" ], "Actions": { "EventAction": "NO_ACTION" } } } }

下列程式碼範例示範如何使用 set-ui-customization

AWS CLI

設定 UI 自訂

此範例會自訂使用者集區的CSS設定。

命令:

aws cognito-idp set-ui-customization --user-pool-id us-west-2_aaaaaaaaa --css ".logo-customizable {\n\tmax-width: 60%;\n\tmax-height: 30%;\n}\n.banner-customizable {\n\tpadding: 25px 0px 25px 10px;\n\tbackground-color: lightgray;\n}\n.label-customizable {\n\tfont-weight: 300;\n}\n.textDescription-customizable {\n\tpadding-top: 10px;\n\tpadding-bottom: 10px;\n\tdisplay: block;\n\tfont-size: 16px;\n}\n.idpDescription-customizable {\n\tpadding-top: 10px;\n\tpadding-bottom: 10px;\n\tdisplay: block;\n\tfont-size: 16px;\n}\n.legalText-customizable {\n\tcolor: #747474;\n\tfont-size: 11px;\n}\n.submitButton-customizable {\n\tfont-size: 14px;\n\tfont-weight: bold;\n\tmargin: 20px 0px 10px 0px;\n\theight: 40px;\n\twidth: 100%;\n\tcolor: #fff;\n\tbackground-color: #337ab7;\n}\n.submitButton-customizable:hover {\n\tcolor: #fff;\n\tbackground-color: #286090;\n}\n.errorMessage-customizable {\n\tpadding: 5px;\n\tfont-size: 14px;\n\twidth: 100%;\n\tbackground: #F5F5F5;\n\tborder: 2px solid #D64958;\n\tcolor: #D64958;\n}\n.inputField-customizable {\n\twidth: 100%;\n\theight: 34px;\n\tcolor: #555;\n\tbackground-color: #fff;\n\tborder: 1px solid #ccc;\n}\n.inputField-customizable:focus {\n\tborder-color: #66afe9;\n\toutline: 0;\n}\n.idpButton-customizable {\n\theight: 40px;\n\twidth: 100%;\n\ttext-align: center;\n\tmargin-bottom: 15px;\n\tcolor: #fff;\n\tbackground-color: #5bc0de;\n\tborder-color: #46b8da;\n}\n.idpButton-customizable:hover {\n\tcolor: #fff;\n\tbackground-color: #31b0d5;\n}\n.socialButton-customizable {\n\theight: 40px;\n\ttext-align: left;\n\twidth: 100%;\n\tmargin-bottom: 15px;\n}\n.redirect-customizable {\n\ttext-align: center;\n}\n.passwordCheck-notValid-customizable {\n\tcolor: #DF3312;\n}\n.passwordCheck-valid-customizable {\n\tcolor: #19BF00;\n}\n.background-customizable {\n\tbackground-color: #faf;\n}\n"

輸出:

{ "UICustomization": { "UserPoolId": "us-west-2_aaaaaaaaa", "ClientId": "ALL", "CSS": ".logo-customizable {\n\tmax-width: 60%;\n\tmax-height: 30%;\n}\n.banner-customizable {\n\tpadding: 25px 0px 25px 10px;\n\tbackground-color: lightgray;\n}\n.label-customizable {\n\tfont-weight: 300;\n}\n.textDescription-customizable {\n\tpadding-top: 10px;\n\tpadding-bottom: 10px;\n\tdisplay: block;\n\tfont-size: 16px;\n}\n.idpDescription-customizable {\n\tpadding-top: 10px;\n\tpadding-bottom: 10px;\n\tdisplay: block;\n\tfont-size: 16px;\n}\n.legalText-customizable {\n\tcolor: #747474;\n\tfont-size: 11px;\n}\n.submitButton-customizable {\n\tfont-size: 14px;\n\tfont-weight: bold;\n\tmargin: 20px 0px 10px 0px;\n\theight: 40px;\n\twidth: 100%;\n\tcolor: #fff;\n\tbackground-color: #337ab7;\n}\n.submitButton-customizable:hover {\n\tcolor: #fff;\n\tbackground-color: #286090;\n}\n.errorMessage-customizable {\n\tpadding: 5px;\n\tfont-size: 14px;\n\twidth: 100%;\n\tbackground: #F5F5F5;\n\tborder: 2px solid #D64958;\n\tcolor: #D64958;\n}\n.inputField-customizable {\n\twidth: 100%;\n\theight: 34px;\n\tcolor: #555;\n\tbackground-color: #fff;\n\tborder: 1px solid #ccc;\n}\n.inputField-customizable:focus {\n\tborder-color: #66afe9;\n\toutline: 0;\n}\n.idpButton-customizable {\n\theight: 40px;\n\twidth: 100%;\n\ttext-align: center;\n\tmargin-bottom: 15px;\n\tcolor: #fff;\n\tbackground-color: #5bc0de;\n\tborder-color: #46b8da;\n}\n.idpButton-customizable:hover {\n\tcolor: #fff;\n\tbackground-color: #31b0d5;\n}\n.socialButton-customizable {\n\theight: 40px;\n\ttext-align: left;\n\twidth: 100%;\n\tmargin-bottom: 15px;\n}\n.redirect-customizable {\n\ttext-align: center;\n}\n.passwordCheck-notValid-customizable {\n\tcolor: #DF3312;\n}\n.passwordCheck-valid-customizable {\n\tcolor: #19BF00;\n}\n.background-customizable {\n\tbackground-color: #faf;\n}\n", "CSSVersion": "20190129172214" } }

下列程式碼範例示範如何使用 set-user-mfa-preference

AWS CLI

設定使用者MFA設定

下列set-user-mfa-preference範例會修改MFA交付選項。它將MFA交付媒體變更為 SMS。

aws cognito-idp set-user-mfa-preference \ --access-token "eyJra12345EXAMPLE" \ --software-token-mfa-settings Enabled=true,PreferredMfa=true \ --sms-mfa-settings Enabled=false,PreferredMfa=false

此命令不會產生輸出。

如需詳細資訊,請參閱 Amazon Cognito 開發人員指南 中的MFA新增至使用者集區。

下列程式碼範例示範如何使用 set-user-settings

AWS CLI

設定使用者設定

此範例會將MFA交付偏好設定設定為 EMAIL。

命令:

aws cognito-idp set-user-settings --access-token ACCESS_TOKEN --mfa-options DeliveryMedium=EMAIL
  • 如需API詳細資訊,請參閱 命令參考 SetUserSettings中的 。 AWS CLI

下列程式碼範例示範如何使用 sign-up

AWS CLI

若要將使用者登出

此範例註冊了 jane@example.com。

命令:

aws cognito-idp sign-up --client-id 3n4b5urk1ft4fl3mg5e62d9ado --username jane@example.com --password PASSWORD --user-attributes Name="email",Value="jane@example.com" Name="name",Value="Jane"

輸出:

{ "UserConfirmed": false, "UserSub": "e04d60a6-45dc-441c-a40b-e25a787d4862" }
  • 如需API詳細資訊,請參閱 命令參考 SignUp中的 。 AWS CLI

下列程式碼範例示範如何使用 start-user-import-job

AWS CLI

啟動使用者匯入任務

此範例會啟動使用者輸入任務。

如需匯入使用者的詳細資訊,請參閱從CSV檔案將使用者匯入使用者集區。

命令:

aws cognito-idp start-user-import-job --user-pool-id us-west-2_aaaaaaaaa --job-id import-TZqNQvDRnW

輸出:

{ "UserImportJob": { "JobName": "import-Test10", "JobId": "import-lmpxSOuIzH", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED_URL", "CreationDate": 1548278378.928, "StartDate": 1548278397.334, "Status": "Pending", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 0 } }

下列程式碼範例示範如何使用 stop-user-import-job

AWS CLI

停止使用者匯入任務

此範例會停止使用者輸入任務。

如需匯入使用者的詳細資訊,請參閱從CSV檔案將使用者匯入使用者集區。

命令:

aws cognito-idp stop-user-import-job --user-pool-id us-west-2_aaaaaaaaa --job-id import-TZqNQvDRnW

輸出:

{ "UserImportJob": { "JobName": "import-Test5", "JobId": "import-Fx0kARISFL", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED_URL", "CreationDate": 1548278576.259, "StartDate": 1548278623.366, "CompletionDate": 1548278626.741, "Status": "Stopped", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 0, "CompletionMessage": "The Import Job was stopped by the developer." } }

下列程式碼範例示範如何使用 update-auth-event-feedback

AWS CLI

更新驗證事件意見回饋

此範例會更新授權事件意見回饋。它會標記事件「有效」。

命令:

aws cognito-idp update-auth-event-feedback --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --event-id EVENT_ID --feedback-token FEEDBACK_TOKEN --feedback-value "Valid"

下列程式碼範例示範如何使用 update-device-status

AWS CLI

更新裝置狀態

此範例會將裝置的狀態更新為「not_remembered」。

命令:

aws cognito-idp update-device-status --access-token ACCESS_TOKEN --device-key DEVICE_KEY --device-remembered-status "not_remembered"

下列程式碼範例示範如何使用 update-group

AWS CLI

更新群組

此範例會更新 的描述和優先順序 MyGroup。

命令:

aws cognito-idp update-group --user-pool-id us-west-2_aaaaaaaaa --group-name MyGroup --description "New description" --precedence 2

輸出:

{ "Group": { "GroupName": "MyGroup", "UserPoolId": "us-west-2_aaaaaaaaa", "Description": "New description", "RoleArn": "arn:aws:iam::111111111111:role/MyRole", "Precedence": 2, "LastModifiedDate": 1548800862.812, "CreationDate": 1548097827.125 } }
  • 如需API詳細資訊,請參閱 命令參考 UpdateGroup中的 。 AWS CLI

下列程式碼範例示範如何使用 update-resource-server

AWS CLI

更新資源伺服器

此範例會更新資源伺服器天氣。它會新增一個範圍。

命令:

aws cognito-idp update-resource-server --user-pool-id us-west-2_aaaaaaaaa --identifier weather.example.com --name Weather --scopes ScopeName=NewScope,ScopeDescription="New scope description"

輸出:

{ "ResourceServer": { "UserPoolId": "us-west-2_aaaaaaaaa", "Identifier": "weather.example.com", "Name": "Happy", "Scopes": [ { "ScopeName": "NewScope", "ScopeDescription": "New scope description" } ] } }

下列程式碼範例示範如何使用 update-user-attributes

AWS CLI

更新使用者屬性

此範例會更新使用者屬性 "nickname"。

命令:

aws cognito-idp update-user-attributes --access-token ACCESS_TOKEN --user-attributes Name="nickname",Value="Dan"

下列程式碼範例示範如何使用 update-user-pool-client

AWS CLI

更新使用者集區用戶端

此範例會更新使用者集區用戶端的名稱。它也會新增可寫入屬性 "nickname"。

命令:

aws cognito-idp update-user-pool-client --user-pool-id us-west-2_aaaaaaaaa --client-id 3n4b5urk1ft4fl3mg5e62d9ado --client-name "NewClientName" --write-attributes "nickname"

輸出:

{ "UserPoolClient": { "UserPoolId": "us-west-2_aaaaaaaaa", "ClientName": "NewClientName", "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado", "LastModifiedDate": 1548802761.334, "CreationDate": 1548178931.258, "RefreshTokenValidity": 30, "WriteAttributes": [ "nickname" ], "AllowedOAuthFlowsUserPoolClient": false } }

下列程式碼範例示範如何使用 update-user-pool

AWS CLI

更新使用者集區

下列update-user-pool範例使用每個可用組態選項的範例語法修改使用者集區。若要更新使用者集區,您必須指定所有先前設定的選項,否則這些選項會重設為預設值。

aws cognito-idp update-user-pool --user-pool-id us-west-2_EXAMPLE \ --policies PasswordPolicy=\{MinimumLength=6,RequireUppercase=true,RequireLowercase=true,RequireNumbers=true,RequireSymbols=true,TemporaryPasswordValidityDays=7\} \ --deletion-protection ACTIVE \ --lambda-config PreSignUp="arn:aws:lambda:us-west-2:123456789012:function:cognito-test-presignup-function",PreTokenGeneration="arn:aws:lambda:us-west-2:123456789012:function:cognito-test-pretoken-function" \ --auto-verified-attributes "phone_number" "email" \ --verification-message-template \{\"SmsMessage\":\""Your code is {####}"\",\"EmailMessage\":\""Your code is {####}"\",\"EmailSubject\":\""Your verification code"\",\"EmailMessageByLink\":\""Click {##here##} to verify your email address."\",\"EmailSubjectByLink\":\""Your verification link"\",\"DefaultEmailOption\":\"CONFIRM_WITH_LINK\"\} \ --sms-authentication-message "Your code is {####}" \ --user-attribute-update-settings AttributesRequireVerificationBeforeUpdate="email","phone_number" \ --mfa-configuration "OPTIONAL" \ --device-configuration ChallengeRequiredOnNewDevice=true,DeviceOnlyRememberedOnUserPrompt=true \ --email-configuration SourceArn="arn:aws:ses:us-west-2:123456789012:identity/admin@example.com",ReplyToEmailAddress="amdin+noreply@example.com",EmailSendingAccount=DEVELOPER,From="admin@amazon.com",ConfigurationSet="test-configuration-set" \ --sms-configuration SnsCallerArn="arn:aws:iam::123456789012:role/service-role/SNS-SMS-Role",ExternalId="12345",SnsRegion="us-west-2" \ --admin-create-user-config AllowAdminCreateUserOnly=false,InviteMessageTemplate=\{SMSMessage=\""Welcome {username}. Your confirmation code is {####}"\",EmailMessage=\""Welcome {username}. Your confirmation code is {####}"\",EmailSubject=\""Welcome to MyMobileGame"\"\} \ --user-pool-tags "Function"="MyMobileGame","Developers"="Berlin" \ --admin-create-user-config AllowAdminCreateUserOnly=false,InviteMessageTemplate=\{SMSMessage=\""Welcome {username}. Your confirmation code is {####}"\",EmailMessage=\""Welcome {username}. Your confirmation code is {####}"\",EmailSubject=\""Welcome to MyMobileGame"\"\} \ --user-pool-add-ons AdvancedSecurityMode="AUDIT" \ --account-recovery-setting RecoveryMechanisms=\[\{Priority=1,Name="verified_email"\},\{Priority=2,Name="verified_phone_number"\}\]

此命令不會產生輸出。

如需詳細資訊,請參閱 Amazon Cognito 開發人員指南 中的更新使用者集區組態

  • 如需API詳細資訊,請參閱 命令參考 UpdateUserPool中的 。 AWS CLI