Doc AWS SDK 예제 GitHub 리포지토리에서 더 많은 SDK 예제를 사용할 수 있습니다. AWS
기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
AWS SDK와 ListDomainNames 함께 사용
다음 코드 예시는 ListDomainNames의 사용 방법을 보여 줍니다.
작업 예제는 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 다음 코드 예제에서 컨텍스트 내 이 작업을 확인할 수 있습니다.
- Java
-
- SDK for Java 2.x
-
/**
* 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
});
}
- Kotlin
-
- SDK for Kotlin
-
suspend fun listAllDomains() {
OpenSearchClient.fromEnvironment { region = "us-east-1" }.use { searchClient ->
val response: ListDomainNamesResponse = searchClient.listDomainNames(ListDomainNamesRequest {})
response.domainNames?.forEach { domain ->
println("Domain name is " + domain.domainName)
}
}
}