AWS SDK 또는 ListIdentityPools CLI와 함께 사용 - AWS SDK 코드 예제

AWS 문서 AWS SDK 예제 리포지토리에 더 많은 SDK 예제가 있습니다. GitHub

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

AWS SDK 또는 ListIdentityPools CLI와 함께 사용

다음 코드 예제는 ListIdentityPools의 사용 방법을 보여줍니다.

CLI
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.

Java
SDK for Java 2.x
참고

자세한 내용은 에서 확인할 수 GitHub 있습니다. 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); } } }
  • API 세부 정보는 AWS SDK for Java 2.x API ListIdentityPools참조를 참조하십시오.

PowerShell
다음을 위한 도구 PowerShell

예 1: 기존 자격 증명 풀 목록을 검색합니다.

Get-CGIIdentityPoolList

출력:

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
  • API 세부 정보는 AWS Tools for PowerShell Cmdlet 참조를 참조하십시오 ListIdentityPools.

Swift
SDK for Swift
참고

이 사전 릴리스 설명서는 평가판 버전 SDK에 관한 것입니다. 내용은 변경될 수 있습니다.

참고

자세한 내용은 다음과 같습니다. GitHub AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

이름이 지정된 자격 증명 풀의 ID를 찾습니다.

/// 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 }

기존 자격 증명 풀의 ID를 가져오거나 존재하지 않으면 생성합니다.

/// 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 }