Amazon OpenSearch Service Construct Library
See Migrating to OpenSearch for migration instructions from aws-cdk-lib/aws-elasticsearch to this module, aws-cdk-lib/aws-opensearchservice.
Quick start
Create a development cluster by simply specifying the version:
const devDomain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
});
dev_domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0
)
Domain devDomain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.build();
var devDomain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0
});
devDomain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
})
To perform version upgrades without replacing the entire domain, specify the enableVersionUpgrade property.
const devDomain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
enableVersionUpgrade: true, // defaults to false
});
dev_domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
enable_version_upgrade=True
)
Domain devDomain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.enableVersionUpgrade(true)
.build();
var devDomain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
EnableVersionUpgrade = true
});
devDomain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
EnableVersionUpgrade: jsii.Boolean(true),
})
Create a cluster with GP3 volumes:
const gp3Domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_2_5,
ebs: {
volumeSize: 30,
volumeType: ec2.EbsDeviceVolumeType.GP3,
throughput: 125,
iops: 3000,
},
});
from aws_cdk.aws_opensearchservice import EbsOptions
gp3_domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_2_5,
ebs=EbsOptions(
volume_size=30,
volume_type=ec2.EbsDeviceVolumeType.GP3,
throughput=125,
iops=3000
)
)
Domain gp3Domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_2_5)
.ebs(EbsOptions.builder()
.volumeSize(30)
.volumeType(EbsDeviceVolumeType.GP3)
.throughput(125)
.iops(3000)
.build())
.build();
var gp3Domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_2_5,
Ebs = new EbsOptions {
VolumeSize = 30,
VolumeType = EbsDeviceVolumeType.GP3,
Throughput = 125,
Iops = 3000
}
});
gp3Domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_2_5(),
Ebs: &EbsOptions{
VolumeSize: jsii.Number(30),
VolumeType: ec2.EbsDeviceVolumeType_GP3,
Throughput: jsii.Number(125),
Iops: jsii.Number(3000),
},
})
Create a production grade cluster by also specifying things like capacity and az distribution
const prodDomain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
capacity: {
masterNodes: 5,
dataNodes: 20,
},
ebs: {
volumeSize: 20,
},
zoneAwareness: {
availabilityZoneCount: 3,
},
logging: {
slowSearchLogEnabled: true,
appLogEnabled: true,
slowIndexLogEnabled: true,
},
});
from aws_cdk.aws_opensearchservice import CapacityConfig, EbsOptions, ZoneAwarenessConfig, LoggingOptions
prod_domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
capacity=CapacityConfig(
master_nodes=5,
data_nodes=20
),
ebs=EbsOptions(
volume_size=20
),
zone_awareness=ZoneAwarenessConfig(
availability_zone_count=3
),
logging=LoggingOptions(
slow_search_log_enabled=True,
app_log_enabled=True,
slow_index_log_enabled=True
)
)
Domain prodDomain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.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();
var prodDomain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
Capacity = new CapacityConfig {
MasterNodes = 5,
DataNodes = 20
},
Ebs = new EbsOptions {
VolumeSize = 20
},
ZoneAwareness = new ZoneAwarenessConfig {
AvailabilityZoneCount = 3
},
Logging = new LoggingOptions {
SlowSearchLogEnabled = true,
AppLogEnabled = true,
SlowIndexLogEnabled = true
}
});
prodDomain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
Capacity: &CapacityConfig{
MasterNodes: jsii.Number(5),
DataNodes: jsii.Number(20),
},
Ebs: &EbsOptions{
VolumeSize: jsii.Number(20),
},
ZoneAwareness: &ZoneAwarenessConfig{
AvailabilityZoneCount: jsii.Number(3),
},
Logging: &LoggingOptions{
SlowSearchLogEnabled: jsii.Boolean(true),
AppLogEnabled: jsii.Boolean(true),
SlowIndexLogEnabled: jsii.Boolean(true),
},
})
This creates an Amazon OpenSearch Service cluster and automatically sets up log groups for logging the domain logs and slow search logs.
A note about SLR
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 similar to:
Before you can proceed, you must enable a service-linked role to give Amazon OpenSearch Service...
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:
const slr = new iam.CfnServiceLinkedRole(this, 'Service Linked Role', {
awsServiceName: 'es.amazonaws.com',
});
slr = iam.CfnServiceLinkedRole(self, "Service Linked Role",
aws_service_name="es.amazonaws.com"
)
CfnServiceLinkedRole slr = CfnServiceLinkedRole.Builder.create(this, "Service Linked Role")
.awsServiceName("es.amazonaws.com")
.build();
var slr = new CfnServiceLinkedRole(this, "Service Linked Role", new CfnServiceLinkedRoleProps {
AwsServiceName = "es.amazonaws.com"
});
slr := iam.NewCfnServiceLinkedRole(this, jsii.String("Service Linked Role"), &CfnServiceLinkedRoleProps{
AwsServiceName: jsii.String("es.amazonaws.com"),
})
Importing existing domains
Using a known domain endpoint
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:
const domainEndpoint = 'https://my-domain-jcjotrt6f7otem4sqcwbch3c4u.us-east-1.es.amazonaws.com';
const domain = Domain.fromDomainEndpoint(this, 'ImportedDomain', domainEndpoint);
domain_endpoint = "https://my-domain-jcjotrt6f7otem4sqcwbch3c4u.us-east-1.es.amazonaws.com"
domain = Domain.from_domain_endpoint(self, "ImportedDomain", domain_endpoint)
String domainEndpoint = "https://my-domain-jcjotrt6f7otem4sqcwbch3c4u.us-east-1.es.amazonaws.com";
IDomain domain = Domain.fromDomainEndpoint(this, "ImportedDomain", domainEndpoint);
var domainEndpoint = "https://my-domain-jcjotrt6f7otem4sqcwbch3c4u.us-east-1.es.amazonaws.com";
var domain = Domain.FromDomainEndpoint(this, "ImportedDomain", domainEndpoint);
domainEndpoint := "https://my-domain-jcjotrt6f7otem4sqcwbch3c4u.us-east-1.es.amazonaws.com"
domain := awscdk.Domain_FromDomainEndpoint(this, jsii.String("ImportedDomain"), domainEndpoint)
Using the output of another CloudFormation stack
To import an existing domain with the help of an exported value from another CloudFormation stack, use the Domain.fromDomainAttributes factory method. This will accept tokens.
String domainArn = Fn.importValue("another-cf-stack-export-domain-arn");
String domainEndpoint = Fn.importValue("another-cf-stack-export-domain-endpoint");
IDomain domain = Domain.fromDomainAttributes(this, "ImportedDomain", DomainAttributes.builder()
.domainArn(domainArn)
.domainEndpoint(domainEndpoint)
.build());
var domainArn = Fn.ImportValue("another-cf-stack-export-domain-arn");
var domainEndpoint = Fn.ImportValue("another-cf-stack-export-domain-endpoint");
var domain = Domain.FromDomainAttributes(this, "ImportedDomain", new DomainAttributes {
DomainArn = domainArn,
DomainEndpoint = domainEndpoint
});
domainArn := awscdk.Fn_ImportValue(jsii.String("another-cf-stack-export-domain-arn"))
domainEndpoint := awscdk.Fn_ImportValue(jsii.String("another-cf-stack-export-domain-endpoint"))
domain := awscdk.Domain_FromDomainAttributes(this, jsii.String("ImportedDomain"), &DomainAttributes{
DomainArn: jsii.String(DomainArn),
DomainEndpoint: jsii.String(DomainEndpoint),
})
# fn: lambda.Function
# domain: Domain
# Grant write access to the app-search index
domain.grant_index_write("app-search", fn)
# Grant read access to the 'app-search/_search' path
domain.grant_path_read("app-search/_search", fn)
Encryption
The domain can also be created with encryption enabled:
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
ebs: {
volumeSize: 100,
volumeType: ec2.EbsDeviceVolumeType.GENERAL_PURPOSE_SSD,
},
nodeToNodeEncryption: true,
encryptionAtRest: {
enabled: true,
},
});
from aws_cdk.aws_opensearchservice import EbsOptions, EncryptionAtRestOptions
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
ebs=EbsOptions(
volume_size=100,
volume_type=ec2.EbsDeviceVolumeType.GENERAL_PURPOSE_SSD
),
node_to_node_encryption=True,
encryption_at_rest=EncryptionAtRestOptions(
enabled=True
)
)
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.ebs(EbsOptions.builder()
.volumeSize(100)
.volumeType(EbsDeviceVolumeType.GENERAL_PURPOSE_SSD)
.build())
.nodeToNodeEncryption(true)
.encryptionAtRest(EncryptionAtRestOptions.builder()
.enabled(true)
.build())
.build();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
Ebs = new EbsOptions {
VolumeSize = 100,
VolumeType = EbsDeviceVolumeType.GENERAL_PURPOSE_SSD
},
NodeToNodeEncryption = true,
EncryptionAtRest = new EncryptionAtRestOptions {
Enabled = true
}
});
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
Ebs: &EbsOptions{
VolumeSize: jsii.Number(100),
VolumeType: ec2.EbsDeviceVolumeType_GENERAL_PURPOSE_SSD,
},
NodeToNodeEncryption: jsii.Boolean(true),
EncryptionAtRest: &EncryptionAtRestOptions{
Enabled: jsii.Boolean(true),
},
})
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:
import * as kms from 'aws-cdk-lib/aws-kms';
const encryptionKey = new kms.Key(this, 'EncryptionKey');
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
encryptionAtRest: {
kmsKey: encryptionKey,
},
});
from aws_cdk.aws_opensearchservice import EncryptionAtRestOptions
import aws_cdk.aws_kms as kms
encryption_key = kms.Key(self, "EncryptionKey")
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
encryption_at_rest=EncryptionAtRestOptions(
kms_key=encryption_key
)
)
import software.amazon.awscdk.services.kms.*;
Key encryptionKey = new Key(this, "EncryptionKey");
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.encryptionAtRest(EncryptionAtRestOptions.builder()
.kmsKey(encryptionKey)
.build())
.build();
using Amazon.CDK.AWS.KMS;
var encryptionKey = new Key(this, "EncryptionKey");
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
EncryptionAtRest = new EncryptionAtRestOptions {
KmsKey = encryptionKey
}
});
import kms "github.com/aws/aws-cdk-go/awscdk"
encryptionKey := kms.NewKey(this, jsii.String("EncryptionKey"))
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
EncryptionAtRest: &EncryptionAtRestOptions{
KmsKey: encryptionKey,
},
})
The construct also supports using cross-account KMS keys for encryption at rest:
import * as kms from 'aws-cdk-lib/aws-kms';
const crossAccountKey = kms.Key.fromKeyArn(
this,
'CrossAccountKey',
'arn:aws:kms:us-east-1:111111111111:key/12345678-1234-1234-1234-123456789012',
);
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
encryptionAtRest: {
kmsKey: crossAccountKey,
},
});
from aws_cdk.aws_opensearchservice import EncryptionAtRestOptions
import aws_cdk.aws_kms as kms
cross_account_key = kms.Key.from_key_arn(self, "CrossAccountKey", "arn:aws:kms:us-east-1:111111111111:key/12345678-1234-1234-1234-123456789012")
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
encryption_at_rest=EncryptionAtRestOptions(
kms_key=cross_account_key
)
)
import software.amazon.awscdk.services.kms.*;
IKey crossAccountKey = Key.fromKeyArn(this, "CrossAccountKey", "arn:aws:kms:us-east-1:111111111111:key/12345678-1234-1234-1234-123456789012");
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.encryptionAtRest(EncryptionAtRestOptions.builder()
.kmsKey(crossAccountKey)
.build())
.build();
using Amazon.CDK.AWS.KMS;
var crossAccountKey = Key.FromKeyArn(this, "CrossAccountKey", "arn:aws:kms:us-east-1:111111111111:key/12345678-1234-1234-1234-123456789012");
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
EncryptionAtRest = new EncryptionAtRestOptions {
KmsKey = crossAccountKey
}
});
import kms "github.com/aws/aws-cdk-go/awscdk"
crossAccountKey := kms.Key_FromKeyArn(this, jsii.String("CrossAccountKey"), jsii.String("arn:aws:kms:us-east-1:111111111111:key/12345678-1234-1234-1234-123456789012"))
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
EncryptionAtRest: &EncryptionAtRestOptions{
KmsKey: crossAccountKey,
},
})
VPC Support
Domains can be placed inside a VPC, providing a secure communication between Amazon OpenSearch Service and other services within the VPC without the need for an internet gateway, NAT device, or VPN connection.
Visit VPC Support for Amazon OpenSearch Service Domains for more details.
const vpc = new ec2.Vpc(this, 'Vpc');
const domainProps: DomainProps = {
version: EngineVersion.OPENSEARCH_1_0,
removalPolicy: RemovalPolicy.DESTROY,
vpc,
// must be enabled since our VPC contains multiple private subnets.
zoneAwareness: {
enabled: true,
},
capacity: {
// must be an even number since the default az count is 2.
dataNodes: 2,
},
};
new Domain(this, 'Domain', domainProps);
from aws_cdk.aws_opensearchservice import DomainProps, ZoneAwarenessConfig, CapacityConfig
vpc = ec2.Vpc(self, "Vpc")
domain_props = DomainProps(
version=EngineVersion.OPENSEARCH_1_0,
removal_policy=RemovalPolicy.DESTROY,
vpc=vpc,
# must be enabled since our VPC contains multiple private subnets.
zone_awareness=ZoneAwarenessConfig(
enabled=True
),
capacity=CapacityConfig(
# must be an even number since the default az count is 2.
data_nodes=2
)
)
Domain(self, "Domain", domain_props)
Vpc vpc = new Vpc(this, "Vpc");
DomainProps domainProps = DomainProps.builder()
.version(EngineVersion.OPENSEARCH_1_0)
.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);
var vpc = new Vpc(this, "Vpc");
var domainProps = new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
RemovalPolicy = RemovalPolicy.DESTROY,
Vpc = vpc,
// must be enabled since our VPC contains multiple private subnets.
ZoneAwareness = new ZoneAwarenessConfig {
Enabled = true
},
Capacity = new CapacityConfig {
// must be an even number since the default az count is 2.
DataNodes = 2
}
};
new Domain(this, "Domain", domainProps);
vpc := ec2.NewVpc(this, jsii.String("Vpc"))
domainProps := &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
RemovalPolicy: awscdk.RemovalPolicy_DESTROY,
Vpc: Vpc,
// must be enabled since our VPC contains multiple private subnets.
ZoneAwareness: &ZoneAwarenessConfig{
Enabled: jsii.Boolean(true),
},
Capacity: &CapacityConfig{
// must be an even number since the default az count is 2.
DataNodes: jsii.Number(2),
},
}
awscdk.NewDomain(this, jsii.String("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.
Metrics
Helper methods exist to access common domain metrics for example:
declare const domain: Domain;
const freeStorageSpace = domain.metricFreeStorageSpace();
const masterSysMemoryUtilization = domain.metric('MasterSysMemoryUtilization');
# domain: Domain
free_storage_space = domain.metric_free_storage_space()
master_sys_memory_utilization = domain.metric("MasterSysMemoryUtilization")
Domain domain;
Metric freeStorageSpace = domain.metricFreeStorageSpace();
Metric masterSysMemoryUtilization = domain.metric("MasterSysMemoryUtilization");
Domain domain;
var freeStorageSpace = domain.MetricFreeStorageSpace();
var masterSysMemoryUtilization = domain.Metric("MasterSysMemoryUtilization");
var domain Domain
freeStorageSpace := domain.metricFreeStorageSpace()
masterSysMemoryUtilization := domain.metric(jsii.String("MasterSysMemoryUtilization"))
This module is part of the AWS Cloud Development Kit project.
Fine grained access control
The domain can also be created with a master user configured. The password can be supplied or dynamically created if not supplied.
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
enforceHttps: true,
nodeToNodeEncryption: true,
encryptionAtRest: {
enabled: true,
},
fineGrainedAccessControl: {
masterUserName: 'master-user',
},
});
const masterUserPassword = domain.masterUserPassword;
from aws_cdk.aws_opensearchservice import EncryptionAtRestOptions, AdvancedSecurityOptions
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
enforce_https=True,
node_to_node_encryption=True,
encryption_at_rest=EncryptionAtRestOptions(
enabled=True
),
fine_grained_access_control=AdvancedSecurityOptions(
master_user_name="master-user"
)
)
master_user_password = domain.master_user_password
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.enforceHttps(true)
.nodeToNodeEncryption(true)
.encryptionAtRest(EncryptionAtRestOptions.builder()
.enabled(true)
.build())
.fineGrainedAccessControl(AdvancedSecurityOptions.builder()
.masterUserName("master-user")
.build())
.build();
SecretValue masterUserPassword = domain.getMasterUserPassword();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
EnforceHttps = true,
NodeToNodeEncryption = true,
EncryptionAtRest = new EncryptionAtRestOptions {
Enabled = true
},
FineGrainedAccessControl = new AdvancedSecurityOptions {
MasterUserName = "master-user"
}
});
var masterUserPassword = domain.MasterUserPassword;
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
EnforceHttps: jsii.Boolean(true),
NodeToNodeEncryption: jsii.Boolean(true),
EncryptionAtRest: &EncryptionAtRestOptions{
Enabled: jsii.Boolean(true),
},
FineGrainedAccessControl: &AdvancedSecurityOptions{
MasterUserName: jsii.String("master-user"),
},
})
masterUserPassword := domain.MasterUserPassword
SAML authentication
You can enable SAML authentication to use your existing identity provider to offer single sign-on (SSO) for dashboards on Amazon OpenSearch Service domains running OpenSearch or Elasticsearch 6.7 or later. To use SAML authentication, fine-grained access control must be enabled.
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
enforceHttps: true,
nodeToNodeEncryption: true,
encryptionAtRest: {
enabled: true,
},
fineGrainedAccessControl: {
masterUserName: 'master-user',
samlAuthenticationEnabled: true,
samlAuthenticationOptions: {
idpEntityId: 'entity-id',
idpMetadataContent: 'metadata-content-with-quotes-escaped',
},
},
});
from aws_cdk.aws_opensearchservice import EncryptionAtRestOptions, AdvancedSecurityOptions, SAMLOptionsProperty
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
enforce_https=True,
node_to_node_encryption=True,
encryption_at_rest=EncryptionAtRestOptions(
enabled=True
),
fine_grained_access_control=AdvancedSecurityOptions(
master_user_name="master-user",
saml_authentication_enabled=True,
saml_authentication_options=SAMLOptionsProperty(
idp_entity_id="entity-id",
idp_metadata_content="metadata-content-with-quotes-escaped"
)
)
)
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.enforceHttps(true)
.nodeToNodeEncryption(true)
.encryptionAtRest(EncryptionAtRestOptions.builder()
.enabled(true)
.build())
.fineGrainedAccessControl(AdvancedSecurityOptions.builder()
.masterUserName("master-user")
.samlAuthenticationEnabled(true)
.samlAuthenticationOptions(SAMLOptionsProperty.builder()
.idpEntityId("entity-id")
.idpMetadataContent("metadata-content-with-quotes-escaped")
.build())
.build())
.build();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
EnforceHttps = true,
NodeToNodeEncryption = true,
EncryptionAtRest = new EncryptionAtRestOptions {
Enabled = true
},
FineGrainedAccessControl = new AdvancedSecurityOptions {
MasterUserName = "master-user",
SamlAuthenticationEnabled = true,
SamlAuthenticationOptions = new SAMLOptionsProperty {
IdpEntityId = "entity-id",
IdpMetadataContent = "metadata-content-with-quotes-escaped"
}
}
});
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
EnforceHttps: jsii.Boolean(true),
NodeToNodeEncryption: jsii.Boolean(true),
EncryptionAtRest: &EncryptionAtRestOptions{
Enabled: jsii.Boolean(true),
},
FineGrainedAccessControl: &AdvancedSecurityOptions{
MasterUserName: jsii.String("master-user"),
SamlAuthenticationEnabled: jsii.Boolean(true),
SamlAuthenticationOptions: &SAMLOptionsProperty{
IdpEntityId: jsii.String("entity-id"),
IdpMetadataContent: jsii.String("metadata-content-with-quotes-escaped"),
},
},
})
Using unsigned basic auth
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 anonymous 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.
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
useUnsignedBasicAuth: true,
});
const masterUserPassword = domain.masterUserPassword;
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
use_unsigned_basic_auth=True
)
master_user_password = domain.master_user_password
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.useUnsignedBasicAuth(true)
.build();
SecretValue masterUserPassword = domain.getMasterUserPassword();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
UseUnsignedBasicAuth = true
});
var masterUserPassword = domain.MasterUserPassword;
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
UseUnsignedBasicAuth: jsii.Boolean(true),
})
masterUserPassword := domain.MasterUserPassword
Custom access policies
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:
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
accessPolicies: [
new iam.PolicyStatement({
actions: ['es:*ESHttpPost', 'es:ESHttpPut*'],
effect: iam.Effect.ALLOW,
principals: [new iam.AccountPrincipal('123456789012')],
resources: ['*'],
}),
]
});
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
access_policies=[
iam.PolicyStatement(
actions=["es:*ESHttpPost", "es:ESHttpPut*"],
effect=iam.Effect.ALLOW,
principals=[iam.AccountPrincipal("123456789012")],
resources=["*"]
)
]
)
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.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();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
AccessPolicies = new [] {
new PolicyStatement(new PolicyStatementProps {
Actions = new [] { "es:*ESHttpPost", "es:ESHttpPut*" },
Effect = Effect.ALLOW,
Principals = new [] { new AccountPrincipal("123456789012") },
Resources = new [] { "*" }
}) }
});
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
AccessPolicies: []PolicyStatement{
iam.NewPolicyStatement(&PolicyStatementProps{
Actions: []*string{
jsii.String("es:*ESHttpPost"),
jsii.String("es:ESHttpPut*"),
},
Effect: iam.Effect_ALLOW,
Principals: []IPrincipal{
iam.NewAccountPrincipal(jsii.String("123456789012")),
},
Resources: []*string{
jsii.String("*"),
},
}),
},
})
For more complex use-cases, for example, to set the domain up to receive data from a cross-account Amazon Data Firehose the addAccessPolicies helper method allows for policies that include the explicit domain ARN.
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
});
domain.addAccessPolicies(
new iam.PolicyStatement({
actions: ['es:ESHttpPost', 'es:ESHttpPut'],
effect: iam.Effect.ALLOW,
principals: [new iam.AccountPrincipal('123456789012')],
resources: [domain.domainArn, `${domain.domainArn}/*`],
}),
new iam.PolicyStatement({
actions: ['es:ESHttpGet'],
effect: iam.Effect.ALLOW,
principals: [new iam.AccountPrincipal('123456789012')],
resources: [
`${domain.domainArn}/_all/_settings`,
`${domain.domainArn}/_cluster/stats`,
`${domain.domainArn}/index-name*/_mapping/type-name`,
`${domain.domainArn}/roletest*/_mapping/roletest`,
`${domain.domainArn}/_nodes`,
`${domain.domainArn}/_nodes/stats`,
`${domain.domainArn}/_nodes/*/stats`,
`${domain.domainArn}/_stats`,
`${domain.domainArn}/index-name*/_stats`,
`${domain.domainArn}/roletest*/_stat`,
],
}),
);
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0
)
domain.add_access_policies(
iam.PolicyStatement(
actions=["es:ESHttpPost", "es:ESHttpPut"],
effect=iam.Effect.ALLOW,
principals=[iam.AccountPrincipal("123456789012")],
resources=[domain.domain_arn, f"{domain.domainArn}/*"]
),
iam.PolicyStatement(
actions=["es:ESHttpGet"],
effect=iam.Effect.ALLOW,
principals=[iam.AccountPrincipal("123456789012")],
resources=[f"{domain.domainArn}/_all/_settings", f"{domain.domainArn}/_cluster/stats", f"{domain.domainArn}/index-name*/_mapping/type-name", f"{domain.domainArn}/roletest*/_mapping/roletest", f"{domain.domainArn}/_nodes", f"{domain.domainArn}/_nodes/stats", f"{domain.domainArn}/_nodes/*/stats", f"{domain.domainArn}/_stats", f"{domain.domainArn}/index-name*/_stats", f"{domain.domainArn}/roletest*/_stat"
]
))
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.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());
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0
});
domain.AddAccessPolicies(
new PolicyStatement(new PolicyStatementProps {
Actions = new [] { "es:ESHttpPost", "es:ESHttpPut" },
Effect = Effect.ALLOW,
Principals = new [] { new AccountPrincipal("123456789012") },
Resources = new [] { domain.DomainArn, $"{domain.domainArn}/*" }
}),
new PolicyStatement(new PolicyStatementProps {
Actions = new [] { "es:ESHttpGet" },
Effect = Effect.ALLOW,
Principals = new [] { new AccountPrincipal("123456789012") },
Resources = new [] { $"{domain.domainArn}/_all/_settings", $"{domain.domainArn}/_cluster/stats", $"{domain.domainArn}/index-name*/_mapping/type-name", $"{domain.domainArn}/roletest*/_mapping/roletest", $"{domain.domainArn}/_nodes", $"{domain.domainArn}/_nodes/stats", $"{domain.domainArn}/_nodes/*/stats", $"{domain.domainArn}/_stats", $"{domain.domainArn}/index-name*/_stats", $"{domain.domainArn}/roletest*/_stat" }
}));
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
})
domain.AddAccessPolicies(
iam.NewPolicyStatement(&PolicyStatementProps{
Actions: []*string{
jsii.String("es:ESHttpPost"),
jsii.String("es:ESHttpPut"),
},
Effect: iam.Effect_ALLOW,
Principals: []IPrincipal{
iam.NewAccountPrincipal(jsii.String("123456789012")),
},
Resources: []*string{
domain.domainArn,
fmt.Sprintf("%v/*", domain.domainArn),
},
}),
iam.NewPolicyStatement(&PolicyStatementProps{
Actions: []*string{
jsii.String("es:ESHttpGet"),
},
Effect: iam.Effect_ALLOW,
Principals: []IPrincipal{
iam.NewAccountPrincipal(jsii.String("123456789012")),
},
Resources: []*string{
fmt.Sprintf("%v/_all/_settings", domain.domainArn),
fmt.Sprintf("%v/_cluster/stats", domain.domainArn),
fmt.Sprintf("%v/index-name*/_mapping/type-name", domain.domainArn),
fmt.Sprintf("%v/roletest*/_mapping/roletest", domain.domainArn),
fmt.Sprintf("%v/_nodes", domain.domainArn),
fmt.Sprintf("%v/_nodes/stats", domain.domainArn),
fmt.Sprintf("%v/_nodes/*/stats", domain.domainArn),
fmt.Sprintf("%v/_stats", domain.domainArn),
fmt.Sprintf("%v/index-name*/_stats", domain.domainArn),
fmt.Sprintf("%v/roletest*/_stat", domain.domainArn),
},
}))
Audit logs
Audit logs can be enabled for a domain, but only when fine grained access control is enabled.
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
enforceHttps: true,
nodeToNodeEncryption: true,
encryptionAtRest: {
enabled: true,
},
fineGrainedAccessControl: {
masterUserName: 'master-user',
},
logging: {
auditLogEnabled: true,
slowSearchLogEnabled: true,
appLogEnabled: true,
slowIndexLogEnabled: true,
},
});
from aws_cdk.aws_opensearchservice import EncryptionAtRestOptions, AdvancedSecurityOptions, LoggingOptions
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
enforce_https=True,
node_to_node_encryption=True,
encryption_at_rest=EncryptionAtRestOptions(
enabled=True
),
fine_grained_access_control=AdvancedSecurityOptions(
master_user_name="master-user"
),
logging=LoggingOptions(
audit_log_enabled=True,
slow_search_log_enabled=True,
app_log_enabled=True,
slow_index_log_enabled=True
)
)
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.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();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
EnforceHttps = true,
NodeToNodeEncryption = true,
EncryptionAtRest = new EncryptionAtRestOptions {
Enabled = true
},
FineGrainedAccessControl = new AdvancedSecurityOptions {
MasterUserName = "master-user"
},
Logging = new LoggingOptions {
AuditLogEnabled = true,
SlowSearchLogEnabled = true,
AppLogEnabled = true,
SlowIndexLogEnabled = true
}
});
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
EnforceHttps: jsii.Boolean(true),
NodeToNodeEncryption: jsii.Boolean(true),
EncryptionAtRest: &EncryptionAtRestOptions{
Enabled: jsii.Boolean(true),
},
FineGrainedAccessControl: &AdvancedSecurityOptions{
MasterUserName: jsii.String("master-user"),
},
Logging: &LoggingOptions{
AuditLogEnabled: jsii.Boolean(true),
SlowSearchLogEnabled: jsii.Boolean(true),
AppLogEnabled: jsii.Boolean(true),
SlowIndexLogEnabled: jsii.Boolean(true),
},
})
Suppress creating CloudWatch Logs resource policy
When logging is enabled for the domain, the CloudWatch Logs resource policy is created by default. This resource policy is necessary for logging, but since only a maximum of 10 resource policies can be created per region, the maximum number of resource policies may be a problem when enabling logging for several domains. By setting the suppressLogsResourcePolicy option to true, you can suppress the creation of a CloudWatch Logs resource policy.
If you set the suppressLogsResourcePolicy option to true, you must create a resource policy before deployment. Also, to avoid reaching this limit, consider reusing a broader policy that includes multiple log groups.
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
enforceHttps: true,
nodeToNodeEncryption: true,
encryptionAtRest: {
enabled: true,
},
fineGrainedAccessControl: {
masterUserName: 'master-user',
},
logging: {
auditLogEnabled: true,
slowSearchLogEnabled: true,
appLogEnabled: true,
slowIndexLogEnabled: true,
},
suppressLogsResourcePolicy: true,
});
from aws_cdk.aws_opensearchservice import EncryptionAtRestOptions, AdvancedSecurityOptions, LoggingOptions
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
enforce_https=True,
node_to_node_encryption=True,
encryption_at_rest=EncryptionAtRestOptions(
enabled=True
),
fine_grained_access_control=AdvancedSecurityOptions(
master_user_name="master-user"
),
logging=LoggingOptions(
audit_log_enabled=True,
slow_search_log_enabled=True,
app_log_enabled=True,
slow_index_log_enabled=True
),
suppress_logs_resource_policy=True
)
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.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())
.suppressLogsResourcePolicy(true)
.build();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
EnforceHttps = true,
NodeToNodeEncryption = true,
EncryptionAtRest = new EncryptionAtRestOptions {
Enabled = true
},
FineGrainedAccessControl = new AdvancedSecurityOptions {
MasterUserName = "master-user"
},
Logging = new LoggingOptions {
AuditLogEnabled = true,
SlowSearchLogEnabled = true,
AppLogEnabled = true,
SlowIndexLogEnabled = true
},
SuppressLogsResourcePolicy = true
});
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
EnforceHttps: jsii.Boolean(true),
NodeToNodeEncryption: jsii.Boolean(true),
EncryptionAtRest: &EncryptionAtRestOptions{
Enabled: jsii.Boolean(true),
},
FineGrainedAccessControl: &AdvancedSecurityOptions{
MasterUserName: jsii.String("master-user"),
},
Logging: &LoggingOptions{
AuditLogEnabled: jsii.Boolean(true),
SlowSearchLogEnabled: jsii.Boolean(true),
AppLogEnabled: jsii.Boolean(true),
SlowIndexLogEnabled: jsii.Boolean(true),
},
SuppressLogsResourcePolicy: jsii.Boolean(true),
})
Visit Monitoring OpenSearch logs with Amazon CloudWatch Logs for more details.
UltraWarm
UltraWarm nodes can be enabled to provide a cost-effective way to store large amounts of read-only data.
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
capacity: {
masterNodes: 2,
warmNodes: 2,
warmInstanceType: 'ultrawarm1.medium.search',
},
});
from aws_cdk.aws_opensearchservice import CapacityConfig
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
capacity=CapacityConfig(
master_nodes=2,
warm_nodes=2,
warm_instance_type="ultrawarm1.medium.search"
)
)
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.capacity(CapacityConfig.builder()
.masterNodes(2)
.warmNodes(2)
.warmInstanceType("ultrawarm1.medium.search")
.build())
.build();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
Capacity = new CapacityConfig {
MasterNodes = 2,
WarmNodes = 2,
WarmInstanceType = "ultrawarm1.medium.search"
}
});
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
Capacity: &CapacityConfig{
MasterNodes: jsii.Number(2),
WarmNodes: jsii.Number(2),
WarmInstanceType: jsii.String("ultrawarm1.medium.search"),
},
})
Cold storage
Cold storage can be enabled on the domain. You must enable UltraWarm storage to enable cold storage.
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
capacity: {
masterNodes: 2,
warmNodes: 2,
warmInstanceType: 'ultrawarm1.medium.search',
},
coldStorageEnabled: true,
});
from aws_cdk.aws_opensearchservice import CapacityConfig
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
capacity=CapacityConfig(
master_nodes=2,
warm_nodes=2,
warm_instance_type="ultrawarm1.medium.search"
),
cold_storage_enabled=True
)
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.capacity(CapacityConfig.builder()
.masterNodes(2)
.warmNodes(2)
.warmInstanceType("ultrawarm1.medium.search")
.build())
.coldStorageEnabled(true)
.build();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
Capacity = new CapacityConfig {
MasterNodes = 2,
WarmNodes = 2,
WarmInstanceType = "ultrawarm1.medium.search"
},
ColdStorageEnabled = true
});
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
Capacity: &CapacityConfig{
MasterNodes: jsii.Number(2),
WarmNodes: jsii.Number(2),
WarmInstanceType: jsii.String("ultrawarm1.medium.search"),
},
ColdStorageEnabled: jsii.Boolean(true),
})
S3 Vectors Engine
Amazon OpenSearch Service offers the ability to use Amazon S3 as a vector engine for vector indexes. This feature allows you to offload vector data to Amazon S3 while maintaining sub-second vector search capabilities at low cost.
Requirements:
- OpenSearch version 2.19 or later
- OpenSearch Optimized instance types (OR1, OR2, OM2, OI2) for data nodes
- Encryption at rest must be enabled
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_2_19,
s3VectorsEngineEnabled: true,
capacity: {
dataNodeInstanceType: 'or1.medium.search',
},
encryptionAtRest: {
enabled: true,
},
});
from aws_cdk.aws_opensearchservice import CapacityConfig, EncryptionAtRestOptions
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_2_19,
s3_vectors_engine_enabled=True,
capacity=CapacityConfig(
data_node_instance_type="or1.medium.search"
),
encryption_at_rest=EncryptionAtRestOptions(
enabled=True
)
)
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_2_19)
.s3VectorsEngineEnabled(true)
.capacity(CapacityConfig.builder()
.dataNodeInstanceType("or1.medium.search")
.build())
.encryptionAtRest(EncryptionAtRestOptions.builder()
.enabled(true)
.build())
.build();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_2_19,
S3VectorsEngineEnabled = true,
Capacity = new CapacityConfig {
DataNodeInstanceType = "or1.medium.search"
},
EncryptionAtRest = new EncryptionAtRestOptions {
Enabled = true
}
});
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_2_19(),
S3VectorsEngineEnabled: jsii.Boolean(true),
Capacity: &CapacityConfig{
DataNodeInstanceType: jsii.String("or1.medium.search"),
},
EncryptionAtRest: &EncryptionAtRestOptions{
Enabled: jsii.Boolean(true),
},
})
Custom endpoint
Custom endpoints can be configured to reach the domain under a custom domain name.
new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
customEndpoint: {
domainName: 'search.example.com',
},
});
from aws_cdk.aws_opensearchservice import CustomEndpointOptions
Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
custom_endpoint=CustomEndpointOptions(
domain_name="search.example.com"
)
)
Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.customEndpoint(CustomEndpointOptions.builder()
.domainName("search.example.com")
.build())
.build();
new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
CustomEndpoint = new CustomEndpointOptions {
DomainName = "search.example.com"
}
});
awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
CustomEndpoint: &CustomEndpointOptions{
DomainName: jsii.String("search.example.com"),
},
})
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 options
Advanced options can used to configure additional options.
new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
advancedOptions: {
'rest.action.multi.allow_explicit_index': 'false',
'indices.fielddata.cache.size': '25',
'indices.query.bool.max_clause_count': '2048',
},
});
Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
advanced_options={
"rest.action.multi.allow_explicit_index": "false",
"indices.fielddata.cache.size": "25",
"indices.query.bool.max_clause_count": "2048"
}
)
Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.advancedOptions(Map.of(
"rest.action.multi.allow_explicit_index", "false",
"indices.fielddata.cache.size", "25",
"indices.query.bool.max_clause_count", "2048"))
.build();
new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
AdvancedOptions = new Dictionary<string, string> {
{ "rest.action.multi.allow_explicit_index", "false" },
{ "indices.fielddata.cache.size", "25" },
{ "indices.query.bool.max_clause_count", "2048" }
}
});
awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
AdvancedOptions: map[string]*string{
"rest.action.multi.allow_explicit_index": jsii.String("false"),
"indices.fielddata.cache.size": jsii.String("25"),
"indices.query.bool.max_clause_count": jsii.String("2048"),
},
})
Amazon Cognito authentication for OpenSearch Dashboards
The domain can be configured to use Amazon Cognito authentication for OpenSearch Dashboards.
Visit Configuring Amazon Cognito authentication for OpenSearch Dashboards for more details.
declare const cognitoConfigurationRole: iam.Role;
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_0,
cognitoDashboardsAuth: {
role: cognitoConfigurationRole,
identityPoolId: 'example-identity-pool-id',
userPoolId: 'example-user-pool-id',
},
});
from aws_cdk.aws_opensearchservice import CognitoOptions
# cognito_configuration_role: iam.Role
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_0,
cognito_dashboards_auth=CognitoOptions(
role=cognito_configuration_role,
identity_pool_id="example-identity-pool-id",
user_pool_id="example-user-pool-id"
)
)
Role cognitoConfigurationRole;
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_0)
.cognitoDashboardsAuth(CognitoOptions.builder()
.role(cognitoConfigurationRole)
.identityPoolId("example-identity-pool-id")
.userPoolId("example-user-pool-id")
.build())
.build();
Role cognitoConfigurationRole;
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_0,
CognitoDashboardsAuth = new CognitoOptions {
Role = cognitoConfigurationRole,
IdentityPoolId = "example-identity-pool-id",
UserPoolId = "example-user-pool-id"
}
});
var cognitoConfigurationRole Role
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_0(),
CognitoDashboardsAuth: &CognitoOptions{
Role: cognitoConfigurationRole,
IdentityPoolId: jsii.String("example-identity-pool-id"),
UserPoolId: jsii.String("example-user-pool-id"),
},
})
Enable support for Multi-AZ with Standby deployment
The domain can be configured to use multi-AZ with standby.
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_3,
ebs: {
volumeSize: 10,
volumeType: ec2.EbsDeviceVolumeType.GENERAL_PURPOSE_SSD_GP3,
},
zoneAwareness: {
enabled: true,
availabilityZoneCount: 3,
},
capacity: {
multiAzWithStandbyEnabled: true,
masterNodes: 3,
dataNodes: 3,
},
});
from aws_cdk.aws_opensearchservice import EbsOptions, ZoneAwarenessConfig, CapacityConfig
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_3,
ebs=EbsOptions(
volume_size=10,
volume_type=ec2.EbsDeviceVolumeType.GENERAL_PURPOSE_SSD_GP3
),
zone_awareness=ZoneAwarenessConfig(
enabled=True,
availability_zone_count=3
),
capacity=CapacityConfig(
multi_az_with_standby_enabled=True,
master_nodes=3,
data_nodes=3
)
)
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_3)
.ebs(EbsOptions.builder()
.volumeSize(10)
.volumeType(EbsDeviceVolumeType.GENERAL_PURPOSE_SSD_GP3)
.build())
.zoneAwareness(ZoneAwarenessConfig.builder()
.enabled(true)
.availabilityZoneCount(3)
.build())
.capacity(CapacityConfig.builder()
.multiAzWithStandbyEnabled(true)
.masterNodes(3)
.dataNodes(3)
.build())
.build();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_3,
Ebs = new EbsOptions {
VolumeSize = 10,
VolumeType = EbsDeviceVolumeType.GENERAL_PURPOSE_SSD_GP3
},
ZoneAwareness = new ZoneAwarenessConfig {
Enabled = true,
AvailabilityZoneCount = 3
},
Capacity = new CapacityConfig {
MultiAzWithStandbyEnabled = true,
MasterNodes = 3,
DataNodes = 3
}
});
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_3(),
Ebs: &EbsOptions{
VolumeSize: jsii.Number(10),
VolumeType: ec2.EbsDeviceVolumeType_GENERAL_PURPOSE_SSD_GP3,
},
ZoneAwareness: &ZoneAwarenessConfig{
Enabled: jsii.Boolean(true),
AvailabilityZoneCount: jsii.Number(3),
},
Capacity: &CapacityConfig{
MultiAzWithStandbyEnabled: jsii.Boolean(true),
MasterNodes: jsii.Number(3),
DataNodes: jsii.Number(3),
},
})
Define off-peak windows
The domain can be configured to use a daily 10-hour window considered as off-peak hours.
Off-peak windows were introduced on February 16, 2023. All domains created before this date have the off-peak window disabled by default. You must manually enable and configure the off-peak window for these domains. All domains created after this date will have the off-peak window enabled by default. You can't disable the off-peak window for a domain after it's enabled.
Visit Defining off-peak windows for Amazon OpenSearch Service for more details.
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_3,
offPeakWindowEnabled: true, // can be omitted if offPeakWindowStart is set
offPeakWindowStart: {
hours: 20,
minutes: 0,
},
});
from aws_cdk.aws_opensearchservice import WindowStartTime
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_3,
off_peak_window_enabled=True, # can be omitted if offPeakWindowStart is set
off_peak_window_start=WindowStartTime(
hours=20,
minutes=0
)
)
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_3)
.offPeakWindowEnabled(true) // can be omitted if offPeakWindowStart is set
.offPeakWindowStart(WindowStartTime.builder()
.hours(20)
.minutes(0)
.build())
.build();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_3,
OffPeakWindowEnabled = true, // can be omitted if offPeakWindowStart is set
OffPeakWindowStart = new WindowStartTime {
Hours = 20,
Minutes = 0
}
});
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_3(),
OffPeakWindowEnabled: jsii.Boolean(true),
// can be omitted if offPeakWindowStart is set
OffPeakWindowStart: &WindowStartTime{
Hours: jsii.Number(20),
Minutes: jsii.Number(0),
},
})
Configuring service software updates
The domain can be configured to use service software updates.
Visit Service software updates in Amazon OpenSearch Service for more details.
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_3,
enableAutoSoftwareUpdate: true,
useLatestServiceSoftwareForBlueGreen: true,
});
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_3,
enable_auto_software_update=True,
use_latest_service_software_for_blue_green=True
)
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_3)
.enableAutoSoftwareUpdate(true)
.useLatestServiceSoftwareForBlueGreen(true)
.build();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_3,
EnableAutoSoftwareUpdate = true,
UseLatestServiceSoftwareForBlueGreen = true
});
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_3(),
EnableAutoSoftwareUpdate: jsii.Boolean(true),
UseLatestServiceSoftwareForBlueGreen: jsii.Boolean(true),
})
IP address type
You can specify either dual stack or IPv4 as your IP address type.
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_3,
ipAddressType: IpAddressType.DUAL_STACK,
});
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_3,
ip_address_type=IpAddressType.DUAL_STACK
)
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_3)
.ipAddressType(IpAddressType.DUAL_STACK)
.build();
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_3,
IpAddressType = IpAddressType.DUAL_STACK
});
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_3(),
IpAddressType: awscdk.IpAddressType_DUAL_STACK,
})
Using Coordinator node with NodeOptions
You can specify coordinator as a valid value for node type.
Visit Dedicated coordinator nodes in Amazon OpenSearch Service for more details.
import * as opensearch from 'aws-cdk-lib/aws-opensearchservice';
const domain = new Domain(this, 'Domain', {
version: EngineVersion.OPENSEARCH_1_3,
capacity: {
nodeOptions: [
{
nodeType: opensearch.NodeType.COORDINATOR,
nodeConfig: {
enabled: true,
count: 2,
type: 'm5.large.search',
},
},
],
},
})
import aws_cdk.aws_opensearchservice as opensearch
domain = Domain(self, "Domain",
version=EngineVersion.OPENSEARCH_1_3,
capacity=opensearch.CapacityConfig(
node_options=[opensearch.NodeOptions(
node_type=opensearch.NodeType.COORDINATOR,
node_config=opensearch.NodeConfig(
enabled=True,
count=2,
type="m5.large.search"
)
)
]
)
)
import software.amazon.awscdk.services.opensearchservice.*;
Domain domain = Domain.Builder.create(this, "Domain")
.version(EngineVersion.OPENSEARCH_1_3)
.capacity(CapacityConfig.builder()
.nodeOptions(List.of(NodeOptions.builder()
.nodeType(NodeType.COORDINATOR)
.nodeConfig(NodeConfig.builder()
.enabled(true)
.count(2)
.type("m5.large.search")
.build())
.build()))
.build())
.build();
using Amazon.CDK.AWS.OpenSearchService;
var domain = new Domain(this, "Domain", new DomainProps {
Version = EngineVersion.OPENSEARCH_1_3,
Capacity = new CapacityConfig {
NodeOptions = new [] { new NodeOptions {
NodeType = NodeType.COORDINATOR,
NodeConfig = new NodeConfig {
Enabled = true,
Count = 2,
Type = "m5.large.search"
}
} }
}
});
import opensearch "github.com/aws/aws-cdk-go/awscdk"
domain := awscdk.NewDomain(this, jsii.String("Domain"), &DomainProps{
Version: awscdk.EngineVersion_OPENSEARCH_1_3(),
Capacity: &CapacityConfig{
NodeOptions: []NodeOptions{
&NodeOptions{
NodeType: opensearch.NodeType_COORDINATOR,
NodeConfig: &NodeConfig{
Enabled: jsii.Boolean(true),
Count: jsii.Number(2),
Type: jsii.String("m5.large.search"),
},
},
},
},
})
Types
Constructs (L2)
DomainConstruct (L2)
Provides an Amazon OpenSearch Service domain.
Constructs (L1)
CfnApplicationConstruct (L1)
Creates an OpenSearch UI application.CfnDomainConstruct (L1)
The AWS::OpenSearchService::Domain resource creates an Amazon OpenSearch Service domain.
Structs
AdvancedSecurityOptionsStruct
Specifies options for fine-grained access control.CapacityConfigStruct
Configures the capacity of the cluster such as the instance type and the number of instances.CfnApplication.AppConfigPropertyStruct
Configuration settings for an OpenSearch application.CfnApplication.StructDataSourceProperty
Data sources that are associated with an OpenSearch application.CfnApplication.StructIamIdentityCenterOptionsProperty
Configuration settings for IAM Identity Center in an OpenSearch application.CfnApplicationPropsStruct
Properties for defining aCfnApplication.CfnDomain.StructAdvanced Security Options Input Property
Specifies options for fine-grained access control.CfnDomain.AIMLOptionsPropertyStructCfnDomain.StructAutomated Snapshot Pause Options Property CfnDomain.ClusterConfigPropertyStruct
The cluster configuration for the OpenSearch Service domain.CfnDomain.CognitoOptionsPropertyStruct
Configures OpenSearch Service to use Amazon Cognito authentication for OpenSearch Dashboards.CfnDomain.StructColdStorageOptionsProperty
Container for the parameters required to enable cold storage for an OpenSearch Service domain.CfnDomain.StructDeployment Strategy Options Property CfnDomain.StructDomainEndpointOptionsProperty
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.EBSOptionsPropertyStruct
The configurations of Amazon Elastic Block Store (Amazon EBS) volumes that are attached to data nodes in the OpenSearch Service domain.CfnDomain.StructEncryptionAtRestOptionsProperty
Whether the domain should encrypt data at rest, and if so, the AWS Key Management Service key to use.CfnDomain.StructIAMFederationOptionsProperty CfnDomain.StructIdentityCenterOptionsProperty
Settings container for integrating IAM Identity Center with OpenSearch UI applications, which enables enabling secure user authentication and access control across multiple data sources.CfnDomain.IdpPropertyStruct
The SAML Identity Provider's information.CfnDomain.JWTOptionsPropertyStructCfnDomain.StructLogPublishingOptionProperty
Specifies whether the OpenSearch Service domain publishes application, search slow logs, or index slow logs to Amazon CloudWatch.CfnDomain.StructMasterUserOptionsProperty
Specifies information about the master user.CfnDomain.NodeConfigPropertyStruct
Configuration options for defining the setup of any node type within the cluster.CfnDomain.NodeOptionPropertyStruct
Configuration settings for defining the node type within a cluster.CfnDomain.StructNode To Node Encryption Options Property
Specifies options for node-to-node encryption.CfnDomain.StructOffPeakWindowOptionsProperty
Off-peak window settings for the domain.CfnDomain.OffPeakWindowPropertyStruct
A custom 10-hour, low-traffic window during which OpenSearch Service can perform mandatory configuration changes on the domain.CfnDomain.StructS3VectorsEngineProperty
Options for enabling S3 vectors engine features on the specified domain.CfnDomain.SAMLOptionsPropertyStruct
Container for information about the SAML configuration for OpenSearch Dashboards.CfnDomain.StructServerless Vector Acceleration Property CfnDomain.StructServiceSoftwareOptionsProperty
The current status of the service software for an Amazon OpenSearch Service domain.CfnDomain.StructSnapshotOptionsProperty
DEPRECATED .CfnDomain.StructSoftwareUpdateOptionsProperty
Options for configuring service software updates for a domain.CfnDomain.VPCOptionsPropertyStruct
The virtual private cloud (VPC) configuration for the OpenSearch Service domain.CfnDomain.StructWindowStartTimeProperty
A custom start time for the off-peak window, in Coordinated Universal Time (UTC).CfnDomain.StructZoneAwarenessConfigProperty
Specifies zone awareness configuration options.CfnDomainPropsStruct
Properties for defining aCfnDomain.CognitoOptionsStruct
Configures Amazon OpenSearch Service to use Amazon Cognito authentication for OpenSearch Dashboards.CustomEndpointOptionsStruct
Configures a custom domain endpoint for the Amazon OpenSearch Service domain.DomainAttributesStruct
Reference to an Amazon OpenSearch Service domain.DomainPropsStruct
Properties for an Amazon OpenSearch Service domain.EbsOptionsStruct
The configurations of Amazon Elastic Block Store (Amazon EBS) volumes that are attached to data nodes in the Amazon OpenSearch Service domain.EncryptionAtRestOptionsStruct
Whether the domain should encrypt data at rest, and if so, the AWS Key Management Service (KMS) key to use.LoggingOptionsStruct
Configures log settings for the domain.NodeConfigStruct
Configuration for a specific node type in OpenSearch domain.NodeOptionsStruct
Configuration for node options in OpenSearch domain.SAMLOptionsPropertyStruct
Container for information about the SAML configuration for OpenSearch Dashboards.WindowStartTimeStructZoneAwarenessConfigStruct
Specifies zone awareness configuration options.
Facades
DomainGrantsFacade
Collection of grant methods for a IDomainRef.
Classes
EngineVersionClass
OpenSearch version.
Interfaces
IDomainInterface
An interface that represents an Amazon OpenSearch Service domain - either created with the CDK, or an existing one.
Enums
IpAddressTypeEnum
The IP address type for the domain.NodeTypeEnum
NodeType is a string enum of the node types in OpenSearch domain.TLSSecurityPolicyEnum
The minimum TLS version required for traffic to the domain.