本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 的 Amazon Cognito Identity 範例 AWS CLI
下列程式碼範例示範如何使用 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 } ] }
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateIdentityPool
。
-
下列程式碼範例示範如何使用 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
。
-
下列程式碼範例示範如何使用 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 } ] }
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeIdentityPool
。
-
下列程式碼範例示範如何使用 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" } }
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetIdentityPoolRoles
。
-
下列程式碼範例示範如何使用 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"-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 SetIdentityPoolRoles
。
-
下列程式碼範例示範如何使用 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 } ] }
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 UpdateIdentityPool
。
-