文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK DeleteDomain 配合使用
以下代码示例演示如何使用 DeleteDomain。
操作示例是大型程序的代码摘录,必须在上下文中运行。您可以在以下代码示例中查看此操作的上下文:
- Java
-
- 适用于 Java 的 SDK 2.x
-
/**
* Deletes a specific domain asynchronously.
* @param domainName the name of the domain to be deleted
* @return a {@link CompletableFuture} that completes when the domain has been deleted
* or throws a {@link RuntimeException} if the deletion fails
*/
public CompletableFuture<DeleteDomainResponse> deleteSpecificDomainAsync(String domainName) {
DeleteDomainRequest domainRequest = DeleteDomainRequest.builder()
.domainName(domainName)
.build();
// Delete domain asynchronously
return getAsyncClient().deleteDomain(domainRequest)
.whenComplete((response, exception) -> {
if (exception != null) {
throw new RuntimeException("Failed to delete the domain: " + domainName, exception);
}
});
}
- Kotlin
-
- 适用于 Kotlin 的 SDK
-
suspend fun deleteSpecificDomain(domainNameVal: String) {
val request =
DeleteDomainRequest {
domainName = domainNameVal
}
OpenSearchClient.fromEnvironment { region = "us-east-1" }.use { searchClient ->
searchClient.deleteDomain(request)
println("$domainNameVal was successfully deleted.")
}
}