文件範例儲存庫中有更多 AWS SDK可用的範例。 AWS SDK
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
CreateDomain
搭配 使用 AWS SDK
下列程式碼範例示範如何使用 CreateDomain
。
動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:
- Java
-
- SDK 適用於 Java 2.x
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 /** * Creates a new OpenSearch domain asynchronously. * @param domainName the name of the new OpenSearch domain to create * @return a {@link CompletableFuture} containing the domain ID of the newly created domain */ public CompletableFuture<String> createNewDomainAsync(String domainName) { ClusterConfig clusterConfig = ClusterConfig.builder() .dedicatedMasterEnabled(true) .dedicatedMasterCount(3) .dedicatedMasterType("t2.small.search") .instanceType("t2.small.search") .instanceCount(5) .build(); EBSOptions ebsOptions = EBSOptions.builder() .ebsEnabled(true) .volumeSize(10) .volumeType(VolumeType.GP2) .build(); NodeToNodeEncryptionOptions encryptionOptions = NodeToNodeEncryptionOptions.builder() .enabled(true) .build(); CreateDomainRequest domainRequest = CreateDomainRequest.builder() .domainName(domainName) .engineVersion("OpenSearch_1.0") .clusterConfig(clusterConfig) .ebsOptions(ebsOptions) .nodeToNodeEncryptionOptions(encryptionOptions) .build(); logger.info("Sending domain creation request..."); return getAsyncClient().createDomain(domainRequest) .handle( (createResponse, throwable) -> { if (createResponse != null) { logger.info("Domain status is {}", createResponse.domainStatus().changeProgressDetails().configChangeStatusAsString()); logger.info("Domain Id is {}", createResponse.domainStatus().domainId()); return createResponse.domainStatus().domainId(); } throw new RuntimeException("Failed to create domain", throwable); }); }
-
如需API詳細資訊,請參閱 參考 CreateDomain中的 。 AWS SDK for Java 2.x API
-
- Kotlin
-
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 suspend fun createNewDomain(domainNameVal: String?) { val clusterConfigOb = ClusterConfig { dedicatedMasterEnabled = true dedicatedMasterCount = 3 dedicatedMasterType = OpenSearchPartitionInstanceType.fromValue("t2.small.search") instanceType = OpenSearchPartitionInstanceType.fromValue("t2.small.search") instanceCount = 5 } val ebsOptionsOb = EbsOptions { ebsEnabled = true volumeSize = 10 volumeType = VolumeType.Gp2 } val encryptionOptionsOb = NodeToNodeEncryptionOptions { enabled = true } val request = CreateDomainRequest { domainName = domainNameVal engineVersion = "OpenSearch_1.0" clusterConfig = clusterConfigOb ebsOptions = ebsOptionsOb nodeToNodeEncryptionOptions = encryptionOptionsOb } println("Sending domain creation request...") OpenSearchClient { region = "us-east-1" }.use { searchClient -> val createResponse = searchClient.createDomain(request) println("Domain status is ${createResponse.domainStatus}") println("Domain Id is ${createResponse.domainStatus?.domainId}") } }
-
如需API詳細資訊,請參閱CreateDomain
中的 AWS SDK for Kotlin API參考 。
-
ChangeProgress
DeleteDomain