Úselo ListIdentityPools con un AWS SDK o CLI - AWS Ejemplos de código de SDK

Hay más ejemplos de AWS SDK disponibles en el GitHub repositorio de ejemplos de AWS Doc SDK.

Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.

Úselo ListIdentityPools con un AWS SDK o CLI

En los siguientes ejemplos de código, se muestra cómo utilizar ListIdentityPools.

CLI
AWS CLI

Para mostrar grupos de identidades

En este ejemplo, se muestran los grupos de identidades. Hay un máximo de 20 identidades en la lista.

Comando:

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

Salida:

{ "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" } ] }
  • Para obtener más información sobre la API, consulte ListIdentityPoolsla Referencia de AWS CLI comandos.

Java
SDK para Java 2.x
nota

Hay más información al respecto GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.cognitoidentity.CognitoIdentityClient; import software.amazon.awssdk.services.cognitoidentity.model.ListIdentityPoolsRequest; import software.amazon.awssdk.services.cognitoidentity.model.ListIdentityPoolsResponse; import software.amazon.awssdk.services.cognitoidentityprovider.model.CognitoIdentityProviderException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class ListIdentityPools { public static void main(String[] args) { CognitoIdentityClient cognitoClient = CognitoIdentityClient.builder() .region(Region.US_EAST_1) .build(); listIdPools(cognitoClient); cognitoClient.close(); } public static void listIdPools(CognitoIdentityClient cognitoClient) { try { ListIdentityPoolsRequest poolsRequest = ListIdentityPoolsRequest.builder() .maxResults(15) .build(); ListIdentityPoolsResponse response = cognitoClient.listIdentityPools(poolsRequest); response.identityPools().forEach(pool -> { System.out.println("Pool ID: " + pool.identityPoolId()); System.out.println("Pool name: " + pool.identityPoolName()); }); } catch (CognitoIdentityProviderException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
  • Para obtener más información sobre la API, consulta ListIdentityPoolsla Referencia AWS SDK for Java 2.x de la API.

PowerShell
Herramientas para PowerShell

Ejemplo 1: recupera una lista de grupos de identidades existentes.

Get-CGIIdentityPoolList

Salida:

IdentityPoolId IdentityPoolName -------------- ---------------- us-east-1:0de2af35-2988-4d0b-b22d-EXAMPLEGUID1 CommonTests1 us-east-1:118d242d-204e-4b88-b803-EXAMPLEGUID2 Tests2 us-east-1:15d49393-ab16-431a-b26e-EXAMPLEGUID3 CommonTests13
  • Para obtener más información sobre la API, consulte la referencia ListIdentityPoolsde AWS Tools for PowerShell cmdlets.

Swift
SDK para Swift
nota

Esto es documentación preliminar para un SDK en versión preliminar. Está sujeta a cambios.

nota

Hay más información al respecto. GitHub Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

Busque el ID de un grupo de identidades con su nombre.

/// Return the ID of the identity pool with the specified name. /// /// - Parameters: /// - name: The name of the identity pool whose ID should be returned. /// /// - Returns: A string containing the ID of the specified identity pool /// or `nil` on error or if not found. /// func getIdentityPoolID(name: String) async throws -> String? { var token: String? = nil // Iterate over the identity pools until a match is found. repeat { /// `token` is a value returned by `ListIdentityPools()` if the /// returned list of identity pools is only a partial list. You /// use the `token` to tell Amazon Cognito that you want to /// continue where you left off previously. If you specify `nil` /// or you don't provide the token, Amazon Cognito will start at /// the beginning. let listPoolsInput = ListIdentityPoolsInput(maxResults: 25, nextToken: token) /// Read pages of identity pools from Cognito until one is found /// whose name matches the one specified in the `name` parameter. /// Return the matching pool's ID. Each time we ask for the next /// page of identity pools, we pass in the token given by the /// previous page. let output = try await cognitoIdentityClient.listIdentityPools(input: listPoolsInput) if let identityPools = output.identityPools { for pool in identityPools { if pool.identityPoolName == name { return pool.identityPoolId! } } } token = output.nextToken } while token != nil return nil }

Obtenga el ID de un grupo de identidades existente o créelo si aún no existe.

/// Return the ID of the identity pool with the specified name. /// /// - Parameters: /// - name: The name of the identity pool whose ID should be returned /// /// - Returns: A string containing the ID of the specified identity pool. /// Returns `nil` if there's an error or if the pool isn't found. /// public func getOrCreateIdentityPoolID(name: String) async throws -> String? { // See if the pool already exists. If it doesn't, create it. guard let poolId = try await self.getIdentityPoolID(name: name) else { return try await self.createIdentityPool(name: name) } return poolId }