将 DeleteDomain 和 AWS SDK 结合使用 - AWS SDK 代码示例

AWS 文档 SDK 示例 GitHub 存储库中还有更多 AWS SDK 示例。

DeleteDomain 和 AWS SDK 结合使用

以下代码示例演示如何使用 DeleteDomain

操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:

Java
适用于 Java 的 SDK 2.x
注意

查看 GitHub,了解更多信息。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** * 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); } }); }
  • 有关 API 详细信息,请参阅《AWS SDK for Java 2.x API Reference》中的 DeleteDomain

Kotlin
适用于 Kotlin 的 SDK
注意

查看 GitHub,了解更多信息。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

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.") } }
  • 有关 API 详细信息,请参阅《AWS SDK for Kotlin API Reference》中的 DeleteDomain