Use ListDomainNames with an AWS SDK - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use ListDomainNames with an AWS SDK

The following code examples show how to use ListDomainNames.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

Java
SDK for Java 2.x
Note

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

/** * Asynchronously lists all the domains in the current AWS account. * @return a {@link CompletableFuture} that, when completed, contains a list of {@link DomainInfo} objects representing * the domains in the account. * @throws RuntimeException if there was a failure while listing the domains. */ public CompletableFuture<List<DomainInfo>> listAllDomainsAsync() { ListDomainNamesRequest namesRequest = ListDomainNamesRequest.builder() .engineType("OpenSearch") .build(); return getAsyncClient().listDomainNames(namesRequest) .handle((response, exception) -> { if (exception != null) { throw new RuntimeException("Failed to list all domains", exception); } return response.domainNames(); // Return the list of domain names on success }); }
  • For API details, see ListDomainNames in AWS SDK for Java 2.x API Reference.

Kotlin
SDK for Kotlin
Note

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

suspend fun listAllDomains() { OpenSearchClient { region = "us-east-1" }.use { searchClient -> val response: ListDomainNamesResponse = searchClient.listDomainNames(ListDomainNamesRequest {}) response.domainNames?.forEach { domain -> println("Domain name is " + domain.domainName) } } }
  • For API details, see ListDomainNames in AWS SDK for Kotlin API reference.