文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
CreateDomain
搭配 a AWS SDK 使用
下列程式碼範例示範如何使用 CreateDomain
。
動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:
- Java
-
- Java 2.x 的 SDK
-
注意
還有更多 on 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 for Kotlin
-
注意
還有更多 on 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 for Kotlin SDK 參考中的 API。
-
ChangeProgress
DeleteDomain