Há mais AWS SDK exemplos disponíveis no GitHub repositório AWS Doc SDK Examples
As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.
Use CreateDomain
com um AWS SDK ou CLI
Os exemplos de códigos a seguir mostram como usar CreateDomain
.
- Java
-
- SDKpara Java 2.x
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository
. import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.opensearch.OpenSearchClient; import software.amazon.awssdk.services.opensearch.model.ClusterConfig; import software.amazon.awssdk.services.opensearch.model.EBSOptions; import software.amazon.awssdk.services.opensearch.model.VolumeType; import software.amazon.awssdk.services.opensearch.model.NodeToNodeEncryptionOptions; import software.amazon.awssdk.services.opensearch.model.CreateDomainRequest; import software.amazon.awssdk.services.opensearch.model.CreateDomainResponse; import software.amazon.awssdk.services.opensearch.model.OpenSearchException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class CreateDomain { public static void main(String[] args) { final String usage = """ Usage: <domainName> Where: domainName - The name of the domain to create. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String domainName = args[0]; Region region = Region.US_EAST_1; OpenSearchClient searchClient = OpenSearchClient.builder() .region(region) .build(); createNewDomain(searchClient, domainName); System.out.println("Done"); } public static void createNewDomain(OpenSearchClient searchClient, String domainName) { try { 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(); System.out.println("Sending domain creation request..."); CreateDomainResponse createResponse = searchClient.createDomain(domainRequest); System.out.println("Domain status is " + createResponse.domainStatus().toString()); System.out.println("Domain Id is " + createResponse.domainStatus().domainId()); } catch (OpenSearchException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
-
Para API obter detalhes, consulte CreateDomainem AWS SDK for Java 2.x APIReferência.
-
- Kotlin
-
- SDKpara Kotlin
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository
. 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}") } }
-
Para API obter detalhes, consulte a CreateDomain
referência AWS SDKdo Kotlin API.
-
Ações
DeleteDomain