Use CreateIdentityPool with an Amazon SDK or CLI - Amazon Cognito
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Use CreateIdentityPool with an Amazon SDK or CLI

The following code examples show how to use CreateIdentityPool.

Amazon CLI

To create an identity pool with Cognito identity pool provider

This example creates an identity pool named MyIdentityPool. It has a Cognito identity pool provider. Unauthenticated identities are not allowed.


aws cognito-identity create-identity-pool --identity-pool-name MyIdentityPool --no-allow-unauthenticated-identities --cognito-identity-providers ProviderName="",ClientId="3n4b5urk1ft4fl3mg5e62d9ado",ServerSideTokenCheck=false


{ "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "MyIdentityPool", "AllowUnauthenticatedIdentities": false, "CognitoIdentityProviders": [ { "ProviderName": "", "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado", "ServerSideTokenCheck": false } ] }
SDK for Java 2.x

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

import; import; import; import; import; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * */ public class CreateIdentityPool { public static void main(String[] args) { final String usage = """ Usage: <identityPoolName>\s Where: identityPoolName - The name to give your identity pool. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String identityPoolName = args[0]; CognitoIdentityClient cognitoClient = CognitoIdentityClient.builder() .region(Region.US_EAST_1) .build(); String identityPoolId = createIdPool(cognitoClient, identityPoolName); System.out.println("Unity pool ID " + identityPoolId); cognitoClient.close(); } public static String createIdPool(CognitoIdentityClient cognitoClient, String identityPoolName) { try { CreateIdentityPoolRequest poolRequest = CreateIdentityPoolRequest.builder() .allowUnauthenticatedIdentities(false) .identityPoolName(identityPoolName) .build(); CreateIdentityPoolResponse response = cognitoClient.createIdentityPool(poolRequest); return response.identityPoolId(); } catch (CognitoIdentityProviderException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; } }
Tools for PowerShell

Example 1: Creates a new Identity Pool which allows unauthenticated identities.

New-CGIIdentityPool -AllowUnauthenticatedIdentities $true -IdentityPoolName CommonTests13


LoggedAt : 8/12/2015 4:56:07 PM AllowUnauthenticatedIdentities : True DeveloperProviderName : IdentityPoolId : us-east-1:15d49393-ab16-431a-b26e-EXAMPLEGUID3 IdentityPoolName : CommonTests13 OpenIdConnectProviderARNs : {} SupportedLoginProviders : {} ResponseMetadata : Amazon.Runtime.ResponseMetadata ContentLength : 136 HttpStatusCode : OK
  • For API details, see CreateIdentityPool in Amazon Tools for PowerShell Cmdlet Reference.

SDK for Swift

This is prerelease documentation for an SDK in preview release. It is subject to change.


There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

Create a new identity pool.

/// Create a new identity pool and return its ID. /// /// - Parameters: /// - name: The name to give the new identity pool. /// /// - Returns: A string containing the newly created pool's ID, or `nil` /// if an error occurred. /// func createIdentityPool(name: String) async throws -> String? { let cognitoInputCall = CreateIdentityPoolInput(developerProviderName: "com.exampleco.CognitoIdentityDemo", identityPoolName: name) let result = try await cognitoIdentityClient.createIdentityPool(input: cognitoInputCall) guard let poolId = result.identityPoolId else { return nil } return poolId }

For a complete list of Amazon SDK developer guides and code examples, see Using this service with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.