See: Description
Interface | Description |
---|---|
AdvancedSecurityOptions | Deprecated
use opensearchservice module instead
|
CapacityConfig | Deprecated
use opensearchservice module instead
|
CfnDomain.AdvancedSecurityOptionsInputProperty |
Specifies options for fine-grained access control.
|
CfnDomain.CognitoOptionsProperty |
Configures OpenSearch Service to use Amazon Cognito authentication for OpenSearch Dashboards.
|
CfnDomain.ColdStorageOptionsProperty |
Specifies options for cold storage.
|
CfnDomain.DomainEndpointOptionsProperty |
Specifies additional options for the domain endpoint, such as whether to require HTTPS for all traffic or whether to use a custom endpoint rather than the default endpoint.
|
CfnDomain.EBSOptionsProperty |
The configurations of Amazon Elastic Block Store (Amazon EBS) volumes that are attached to data nodes in the OpenSearch Service domain.
|
CfnDomain.ElasticsearchClusterConfigProperty |
The cluster configuration for the OpenSearch Service domain.
|
CfnDomain.EncryptionAtRestOptionsProperty |
Whether the domain should encrypt data at rest, and if so, the AWS Key Management Service key to use.
|
CfnDomain.LogPublishingOptionProperty |
> The `AWS::Elasticsearch::Domain` resource is being replaced by the [AWS::OpenSearchService::Domain](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-opensearchservice-domain.html) resource.
|
CfnDomain.MasterUserOptionsProperty |
Specifies information about the master user.
|
CfnDomain.NodeToNodeEncryptionOptionsProperty |
Specifies whether node-to-node encryption is enabled.
|
CfnDomain.SnapshotOptionsProperty |
> The `AWS::Elasticsearch::Domain` resource is being replaced by the [AWS::OpenSearchService::Domain](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-opensearchservice-domain.html) resource.
|
CfnDomain.VPCOptionsProperty |
The virtual private cloud (VPC) configuration for the OpenSearch Service domain.
|
CfnDomain.ZoneAwarenessConfigProperty |
Specifies zone awareness configuration options.
|
CfnDomainProps |
Properties for defining a `CfnDomain`.
|
CognitoOptions | Deprecated
use opensearchservice module instead
|
CustomEndpointOptions | Deprecated
use opensearchservice module instead
|
DomainAttributes | Deprecated
use opensearchservice module instead
|
DomainProps | Deprecated
use opensearchservice module instead
|
EbsOptions | Deprecated
use opensearchservice module instead
|
EncryptionAtRestOptions | Deprecated
use opensearchservice module instead
|
IDomain | Deprecated
use opensearchservice module instead
|
IDomain.Jsii$Default |
Internal default implementation for
IDomain . |
LoggingOptions | Deprecated
use opensearchservice module instead
|
ZoneAwarenessConfig | Deprecated
use opensearchservice module instead
|
Enum | Description |
---|---|
TLSSecurityPolicy | Deprecated
use opensearchservice module instead
|
---
This API may emit warnings. Backward compatibility is not guaranteed.
Instead of this module, we recommend using the @aws-cdk/aws-opensearchservice module. See Amazon OpenSearch Service FAQs for details. See Migrating to OpenSearch for migration instructions.
Create a development cluster by simply specifying the version:
Domain devDomain = Domain.Builder.create(this, "Domain") .version(ElasticsearchVersion.V7_1) .build();
To perform version upgrades without replacing the entire domain, specify the enableVersionUpgrade
property.
Domain devDomain = Domain.Builder.create(this, "Domain") .version(ElasticsearchVersion.V7_10) .enableVersionUpgrade(true) .build();
Create a production grade cluster by also specifying things like capacity and az distribution
Domain prodDomain = Domain.Builder.create(this, "Domain") .version(ElasticsearchVersion.V7_1) .capacity(CapacityConfig.builder() .masterNodes(5) .dataNodes(20) .build()) .ebs(EbsOptions.builder() .volumeSize(20) .build()) .zoneAwareness(ZoneAwarenessConfig.builder() .availabilityZoneCount(3) .build()) .logging(LoggingOptions.builder() .slowSearchLogEnabled(true) .appLogEnabled(true) .slowIndexLogEnabled(true) .build()) .build();
This creates an Elasticsearch cluster and automatically sets up log groups for logging the domain logs and slow search logs.
Some cluster configurations (e.g VPC access) require the existence of the AWSServiceRoleForAmazonElasticsearchService
service-linked role.
When performing such operations via the AWS Console, this SLR is created automatically when needed. However, this is not the behavior when using CloudFormation. If an SLR is needed, but doesn't exist, you will encounter a failure message simlar to:
Before you can proceed, you must enable a service-linked role to give Amazon ES...
To resolve this, you need to create the SLR. We recommend using the AWS CLI:
aws iam create-service-linked-role --aws-service-name es.amazonaws.com
You can also create it using the CDK, but note that only the first application deploying this will succeed:
CfnServiceLinkedRole slr = CfnServiceLinkedRole.Builder.create(this, "ElasticSLR") .awsServiceName("es.amazonaws.com") .build();
To import an existing domain into your CDK application, use the Domain.fromDomainEndpoint
factory method.
This method accepts a domain endpoint of an already existing domain:
String domainEndpoint = "https://my-domain-jcjotrt6f7otem4sqcwbch3c4u.us-east-1.es.amazonaws.com"; IDomain domain = Domain.fromDomainEndpoint(this, "ImportedDomain", domainEndpoint);
Helper methods also exist for managing access to the domain.
Function fn; Domain domain; // Grant write access to the app-search index domain.grantIndexWrite("app-search", fn); // Grant read access to the 'app-search/_search' path domain.grantPathRead("app-search/_search", fn);
The domain can also be created with encryption enabled:
Domain domain = Domain.Builder.create(this, "Domain") .version(ElasticsearchVersion.V7_4) .ebs(EbsOptions.builder() .volumeSize(100) .volumeType(EbsDeviceVolumeType.GENERAL_PURPOSE_SSD) .build()) .nodeToNodeEncryption(true) .encryptionAtRest(EncryptionAtRestOptions.builder() .enabled(true) .build()) .build();
This sets up the domain with node to node encryption and encryption at rest. You can also choose to supply your own KMS key to use for encryption at rest.
Elasticsearch domains can be placed inside a VPC, providing a secure communication between Amazon ES and other services within the VPC without the need for an internet gateway, NAT device, or VPN connection.
See Launching your Amazon OpenSearch Service domains within a VPC for more details.
Vpc vpc = new Vpc(this, "Vpc"); DomainProps domainProps = DomainProps.builder() .version(ElasticsearchVersion.V7_1) .removalPolicy(RemovalPolicy.DESTROY) .vpc(vpc) // must be enabled since our VPC contains multiple private subnets. .zoneAwareness(ZoneAwarenessConfig.builder() .enabled(true) .build()) .capacity(CapacityConfig.builder() // must be an even number since the default az count is 2. .dataNodes(2) .build()) .build(); new Domain(this, "Domain", domainProps);
In addition, you can use the vpcSubnets
property to control which specific subnets will be used, and the securityGroups
property to control
which security groups will be attached to the domain. By default, CDK will select all private subnets in the VPC, and create one dedicated security group.
Helper methods exist to access common domain metrics for example:
Domain domain; Metric freeStorageSpace = domain.metricFreeStorageSpace(); Metric masterSysMemoryUtilization = domain.metric("MasterSysMemoryUtilization");
This module is part of the AWS Cloud Development Kit project.
The domain can also be created with a master user configured. The password can be supplied or dynamically created if not supplied.
Domain domain = Domain.Builder.create(this, "Domain") .version(ElasticsearchVersion.V7_1) .enforceHttps(true) .nodeToNodeEncryption(true) .encryptionAtRest(EncryptionAtRestOptions.builder() .enabled(true) .build()) .fineGrainedAccessControl(AdvancedSecurityOptions.builder() .masterUserName("master-user") .build()) .build(); SecretValue masterUserPassword = domain.getMasterUserPassword();
For convenience, the domain can be configured to allow unsigned HTTP requests that use basic auth. Unless the domain is configured to be part of a VPC this means anyone can access the domain using the configured master username and password.
To enable unsigned basic auth access the domain is configured with an access policy that allows anyonmous requests, HTTPS required, node to node encryption, encryption at rest and fine grained access control.
If the above settings are not set they will be configured as part of enabling unsigned basic auth. If they are set with conflicting values, an error will be thrown.
If no master user is configured a default master user is created with the
username admin
.
If no password is configured a default master user password is created and
stored in the AWS Secrets Manager as secret. The secret has the prefix
<domain id>MasterUser
.
Domain domain = Domain.Builder.create(this, "Domain") .version(ElasticsearchVersion.V7_1) .useUnsignedBasicAuth(true) .build(); SecretValue masterUserPassword = domain.getMasterUserPassword();
If the domain requires custom access control it can be configured either as a constructor property, or later by means of a helper method.
For simple permissions the accessPolicies
constructor may be sufficient:
Domain domain = Domain.Builder.create(this, "Domain") .version(ElasticsearchVersion.V7_1) .accessPolicies(List.of( PolicyStatement.Builder.create() .actions(List.of("es:*ESHttpPost", "es:ESHttpPut*")) .effect(Effect.ALLOW) .principals(List.of(new AccountPrincipal("123456789012"))) .resources(List.of("*")) .build())) .build();
For more complex use-cases, for example, to set the domain up to receive data from a
cross-account Kinesis Firehose the addAccessPolicies
helper method
allows for policies that include the explicit domain ARN.
Domain domain = Domain.Builder.create(this, "Domain") .version(ElasticsearchVersion.V7_1) .build(); domain.addAccessPolicies( PolicyStatement.Builder.create() .actions(List.of("es:ESHttpPost", "es:ESHttpPut")) .effect(Effect.ALLOW) .principals(List.of(new AccountPrincipal("123456789012"))) .resources(List.of(domain.getDomainArn(), String.format("%s/*", domain.getDomainArn()))) .build(), PolicyStatement.Builder.create() .actions(List.of("es:ESHttpGet")) .effect(Effect.ALLOW) .principals(List.of(new AccountPrincipal("123456789012"))) .resources(List.of(String.format("%s/_all/_settings", domain.getDomainArn()), String.format("%s/_cluster/stats", domain.getDomainArn()), String.format("%s/index-name*/_mapping/type-name", domain.getDomainArn()), String.format("%s/roletest*/_mapping/roletest", domain.getDomainArn()), String.format("%s/_nodes", domain.getDomainArn()), String.format("%s/_nodes/stats", domain.getDomainArn()), String.format("%s/_nodes/*/stats", domain.getDomainArn()), String.format("%s/_stats", domain.getDomainArn()), String.format("%s/index-name*/_stats", domain.getDomainArn()), String.format("%s/roletest*/_stat", domain.getDomainArn()))) .build());
Audit logs can be enabled for a domain, but only when fine-grained access control is enabled.
Domain domain = Domain.Builder.create(this, "Domain") .version(ElasticsearchVersion.V7_1) .enforceHttps(true) .nodeToNodeEncryption(true) .encryptionAtRest(EncryptionAtRestOptions.builder() .enabled(true) .build()) .fineGrainedAccessControl(AdvancedSecurityOptions.builder() .masterUserName("master-user") .build()) .logging(LoggingOptions.builder() .auditLogEnabled(true) .slowSearchLogEnabled(true) .appLogEnabled(true) .slowIndexLogEnabled(true) .build()) .build();
UltraWarm nodes can be enabled to provide a cost-effective way to store large amounts of read-only data.
Domain domain = Domain.Builder.create(this, "Domain") .version(ElasticsearchVersion.V7_10) .capacity(CapacityConfig.builder() .masterNodes(2) .warmNodes(2) .warmInstanceType("ultrawarm1.medium.elasticsearch") .build()) .build();
Custom endpoints can be configured to reach the ES domain under a custom domain name.
Domain.Builder.create(this, "Domain") .version(ElasticsearchVersion.V7_7) .customEndpoint(CustomEndpointOptions.builder() .domainName("search.example.com") .build()) .build();
It is also possible to specify a custom certificate instead of the auto-generated one.
Additionally, an automatic CNAME-Record is created if a hosted zone is provided for the custom endpoint
Advanced cluster settings can used to configure additional options.
Domain.Builder.create(this, "Domain") .version(ElasticsearchVersion.V7_7) .advancedOptions(Map.of( "rest.action.multi.allow_explicit_index", "false", "indices.fielddata.cache.size", "25", "indices.query.bool.max_clause_count", "2048")) .build();
To migrate from this module (@aws-cdk/aws-elasticsearch
) to the new @aws-cdk/aws-opensearchservice
module, you must modify your CDK application to refer to the new module (including some associated changes) and then perform a CloudFormation resource deletion/import.
Make the following modifications to your CDK application to migrate to the @aws-cdk/aws-opensearchservice
module.
'@aws-cdk/aws-opensearchservice
to '@aws-cdk/aws-elasticsearch
.
For example:
import software.amazon.awscdk.services.elasticsearch.*; import software.amazon.awscdk.services.elasticsearch.Domain;
...becomes...
import software.amazon.awscdk.services.opensearchservice.*; import software.amazon.awscdk.services.opensearchservice.Domain;
es.ElasticsearchVersion
with opensearch.EngineVersion
.
For example:
ElasticsearchVersion version = ElasticsearchVersion.V7_1;
...becomes...
EngineVersion version = EngineVersion.ELASTICSEARCH_7_1;
cognitoKibanaAuth
property of DomainProps
with cognitoDashboardsAuth
.
For example:
Domain.Builder.create(this, "Domain") .cognitoKibanaAuth(CognitoOptions.builder() .identityPoolId("test-identity-pool-id") .userPoolId("test-user-pool-id") .role(role) .build()) .version(elasticsearchVersion) .build();
...becomes...
Domain.Builder.create(this, "Domain") .cognitoDashboardsAuth(CognitoOptions.builder() .identityPoolId("test-identity-pool-id") .userPoolId("test-user-pool-id") .role(role) .build()) .version(openSearchVersion) .build();
.elasticsearch
to .search
.
For example:
Domain.Builder.create(this, "Domain") .capacity(CapacityConfig.builder() .masterNodeInstanceType("r5.large.elasticsearch") .build()) .version(elasticsearchVersion) .build();
...becomes...
Domain.Builder.create(this, "Domain") .capacity(CapacityConfig.builder() .masterNodeInstanceType("r5.large.search") .build()) .version(openSearchVersion) .build();
CfnInclude
'd domains will need to be re-written in their original template in
order to be successfully included as a opensearch.CfnDomain
Follow these steps to migrate your application without data loss:
RemovalPolicy.RETAIN
. This is the default for the domain construct, so nothing is required unless you have specifically set the removal policy to some other value.@aws-cdk/aws-opensearchservice
module by applying the necessary modifications listed above. Synthesize your application and obtain the resulting stack templates.