選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

使用 的 Amazon Cognito Identity 範例 AWS CLI

焦點模式
使用 的 Amazon Cognito Identity 範例 AWS CLI - AWS Command Line Interface

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

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

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

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

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

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

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

主題

動作

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

AWS CLI

若要使用 Cognito 身分集區提供者建立身分集區

此範例會建立名為 MyIdentityPool 的身分集區。它具有 Cognito 身分集區提供者。不允許使用未驗證的身分。

命令:

aws cognito-identity create-identity-pool --identity-pool-name MyIdentityPool --no-allow-unauthenticated-identities --cognito-identity-providers ProviderName="cognito-idp.us-west-2.amazonaws.com/us-west-2_aaaaaaaaa",ClientId="3n4b5urk1ft4fl3mg5e62d9ado",ServerSideTokenCheck=false

輸出:

{ "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "MyIdentityPool", "AllowUnauthenticatedIdentities": false, "CognitoIdentityProviders": [ { "ProviderName": "cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111", "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado", "ServerSideTokenCheck": false } ] }

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

AWS CLI

若要使用 Cognito 身分集區提供者建立身分集區

此範例會建立名為 MyIdentityPool 的身分集區。它具有 Cognito 身分集區提供者。不允許使用未驗證的身分。

命令:

aws cognito-identity create-identity-pool --identity-pool-name MyIdentityPool --no-allow-unauthenticated-identities --cognito-identity-providers ProviderName="cognito-idp.us-west-2.amazonaws.com/us-west-2_aaaaaaaaa",ClientId="3n4b5urk1ft4fl3mg5e62d9ado",ServerSideTokenCheck=false

輸出:

{ "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "MyIdentityPool", "AllowUnauthenticatedIdentities": false, "CognitoIdentityProviders": [ { "ProviderName": "cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111", "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado", "ServerSideTokenCheck": false } ] }

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

AWS CLI

若要刪除身分集區

此範例會刪除身分集區。

命令:

aws cognito-identity delete-identity-pool --identity-ids-to-delete "us-west-2:11111111-1111-1111-1111-111111111111"

輸出:

{ "UnprocessedIdentityIds": [] }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteIdentities

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

AWS CLI

若要刪除身分集區

此範例會刪除身分集區。

命令:

aws cognito-identity delete-identity-pool --identity-ids-to-delete "us-west-2:11111111-1111-1111-1111-111111111111"

輸出:

{ "UnprocessedIdentityIds": [] }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteIdentities

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

AWS CLI

若要刪除身分集區

以下範例 delete-identity-pool 會刪除指定的身分集區。

命令:

aws cognito-identity delete-identity-pool \ --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111"

此命令不會產生輸出。

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 DeleteIdentityPool

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

AWS CLI

若要刪除身分集區

以下範例 delete-identity-pool 會刪除指定的身分集區。

命令:

aws cognito-identity delete-identity-pool \ --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111"

此命令不會產生輸出。

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 DeleteIdentityPool

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

AWS CLI

描述身分集區

此範例說明身分集區。

命令:

aws cognito-identity describe-identity-pool --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111"

輸出:

{ "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "MyIdentityPool", "AllowUnauthenticatedIdentities": false, "CognitoIdentityProviders": [ { "ProviderName": "cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111", "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado", "ServerSideTokenCheck": false } ] }

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

AWS CLI

描述身分集區

此範例說明身分集區。

命令:

aws cognito-identity describe-identity-pool --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111"

輸出:

{ "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "MyIdentityPool", "AllowUnauthenticatedIdentities": false, "CognitoIdentityProviders": [ { "ProviderName": "cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111", "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado", "ServerSideTokenCheck": false } ] }

下列程式碼範例示範如何使用 get-identity-pool-roles

AWS CLI

取得身分集區角色

此範例會取得身分集區角色。

命令:

aws cognito-identity get-identity-pool-roles --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111"

輸出:

{ "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "Roles": { "authenticated": "arn:aws:iam::111111111111:role/Cognito_MyIdentityPoolAuth_Role", "unauthenticated": "arn:aws:iam::111111111111:role/Cognito_MyIdentityPoolUnauth_Role" } }

下列程式碼範例示範如何使用 get-identity-pool-roles

AWS CLI

取得身分集區角色

此範例會取得身分集區角色。

命令:

aws cognito-identity get-identity-pool-roles --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111"

輸出:

{ "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "Roles": { "authenticated": "arn:aws:iam::111111111111:role/Cognito_MyIdentityPoolAuth_Role", "unauthenticated": "arn:aws:iam::111111111111:role/Cognito_MyIdentityPoolUnauth_Role" } }

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

AWS CLI

若要列出身分集區

此範例會列出身分集區。最多列出 20 個身分識別。

命令:

aws cognito-identity list-identity-pools --max-results 20

輸出:

{ "IdentityPools": [ { "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "MyIdentityPool" }, { "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "AnotherIdentityPool" }, { "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "IdentityPoolRegionA" } ] }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 ListIdentityPools

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

AWS CLI

若要列出身分集區

此範例會列出身分集區。最多列出 20 個身分識別。

命令:

aws cognito-identity list-identity-pools --max-results 20

輸出:

{ "IdentityPools": [ { "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "MyIdentityPool" }, { "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "AnotherIdentityPool" }, { "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "IdentityPoolRegionA" } ] }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 ListIdentityPools

下列程式碼範例示範如何使用 set-identity-pool-roles

AWS CLI

設定身分集區角色

下列set-identity-pool-roles範例會設定身分集區角色。

aws cognito-identity set-identity-pool-roles \ --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111" \ --roles authenticated="arn:aws:iam::111111111111:role/Cognito_MyIdentityPoolAuth_Role"

下列程式碼範例示範如何使用 set-identity-pool-roles

AWS CLI

設定身分集區角色

下列set-identity-pool-roles範例會設定身分集區角色。

aws cognito-identity set-identity-pool-roles \ --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111" \ --roles authenticated="arn:aws:iam::111111111111:role/Cognito_MyIdentityPoolAuth_Role"

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

AWS CLI

更新身分集區

此範例會更新身分集區。它會將名稱設定為 MyIdentityPool。它會新增 Cognito 做為身分提供者。它不允許未驗證的身分。

命令:

aws cognito-identity update-identity-pool --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111" --identity-pool-name "MyIdentityPool" --no-allow-unauthenticated-identities --cognito-identity-providers ProviderName="cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111",ClientId="3n4b5urk1ft4fl3mg5e62d9ado",ServerSideTokenCheck=false

輸出:

{ "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "MyIdentityPool", "AllowUnauthenticatedIdentities": false, "CognitoIdentityProviders": [ { "ProviderName": "cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111", "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado", "ServerSideTokenCheck": false } ] }

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

AWS CLI

更新身分集區

此範例會更新身分集區。它會將名稱設定為 MyIdentityPool。它會新增 Cognito 做為身分提供者。它不允許未驗證的身分。

命令:

aws cognito-identity update-identity-pool --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111" --identity-pool-name "MyIdentityPool" --no-allow-unauthenticated-identities --cognito-identity-providers ProviderName="cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111",ClientId="3n4b5urk1ft4fl3mg5e62d9ado",ServerSideTokenCheck=false

輸出:

{ "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "MyIdentityPool", "AllowUnauthenticatedIdentities": false, "CognitoIdentityProviders": [ { "ProviderName": "cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111", "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado", "ServerSideTokenCheck": false } ] }

在本頁面

隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。