This documentation is for Version 1 of the AWS CLI only. For documentation related to Version 2 of the AWS CLI, see the Version 2 User Guide.
OpenSearch Service examples using AWS CLI
The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with OpenSearch Service.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use create-elasticsearch-domain
.
- AWS CLI
-
To create an Amazon Elasticsearch Service domain
The following
create-elasticsearch-domain
command creates a new Amazon Elasticsearch Service domain within a VPC and restricts access to a single user. Amazon ES infers the VPC ID from the specified subnet and security group IDs.aws es create-elasticsearch-domain \ --domain-name
vpc-cli-example
\ --elasticsearch-version6.2
\ --elasticsearch-cluster-configInstanceType=m4.large.elasticsearch,InstanceCount=1
\ --ebs-optionsEBSEnabled=true,VolumeType=standard,VolumeSize=10
\ --access-policies '{"Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": {"AWS": "arn:aws:iam::123456789012:root" }, "Action":"es:*", "Resource": "arn:aws:es:us-west-1:123456789012:domain/vpc-cli-example/*" } ] }
' \ --vpc-optionsSubnetIds=subnet-1a2a3a4a,SecurityGroupIds=sg-2a3a4a5a
Output:
{ "DomainStatus": { "ElasticsearchClusterConfig": { "DedicatedMasterEnabled": false, "InstanceCount": 1, "ZoneAwarenessEnabled": false, "InstanceType": "m4.large.elasticsearch" }, "DomainId": "123456789012/vpc-cli-example", "CognitoOptions": { "Enabled": false }, "VPCOptions": { "SubnetIds": [ "subnet-1a2a3a4a" ], "VPCId": "vpc-3a4a5a6a", "SecurityGroupIds": [ "sg-2a3a4a5a" ], "AvailabilityZones": [ "us-west-1c" ] }, "Created": true, "Deleted": false, "EBSOptions": { "VolumeSize": 10, "VolumeType": "standard", "EBSEnabled": true }, "Processing": true, "DomainName": "vpc-cli-example", "SnapshotOptions": { "AutomatedSnapshotStartHour": 0 }, "ElasticsearchVersion": "6.2", "AccessPolicies": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::123456789012:root\"},\"Action\":\"es:*\",\"Resource\":\"arn:aws:es:us-west-1:123456789012:domain/vpc-cli-example/*\"}]}", "AdvancedOptions": { "rest.action.multi.allow_explicit_index": "true" }, "EncryptionAtRestOptions": { "Enabled": false }, "ARN": "arn:aws:es:us-west-1:123456789012:domain/vpc-cli-example" } }
For more information, see Creating and Managing Amazon Elasticsearch Service Domains in the Amazon Elasticsearch Service Developer Guide.
-
For API details, see CreateElasticsearchDomain
in AWS CLI Command Reference.
-
The following code example shows how to use describe-elasticsearch-domain-config
.
- AWS CLI
-
To get domain configuration details
The following
describe-elasticsearch-domain-config
example provides configuration details for a given domain, along with status information for each individual domain component.aws es describe-elasticsearch-domain-config \ --domain-name
cli-example
Output:
{ "DomainConfig": { "ElasticsearchVersion": { "Options": "7.4", "Status": { "CreationDate": 1589395034.946, "UpdateDate": 1589395827.325, "UpdateVersion": 8, "State": "Active", "PendingDeletion": false } }, "ElasticsearchClusterConfig": { "Options": { "InstanceType": "c5.large.elasticsearch", "InstanceCount": 1, "DedicatedMasterEnabled": true, "ZoneAwarenessEnabled": false, "DedicatedMasterType": "c5.large.elasticsearch", "DedicatedMasterCount": 3, "WarmEnabled": true, "WarmType": "ultrawarm1.medium.elasticsearch", "WarmCount": 2 }, "Status": { "CreationDate": 1589395034.946, "UpdateDate": 1589395827.325, "UpdateVersion": 8, "State": "Active", "PendingDeletion": false } }, "EBSOptions": { "Options": { "EBSEnabled": true, "VolumeType": "gp2", "VolumeSize": 10 }, "Status": { "CreationDate": 1589395034.946, "UpdateDate": 1589395827.325, "UpdateVersion": 8, "State": "Active", "PendingDeletion": false } }, "AccessPolicies": { "Options": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"es:*\",\"Resource\":\"arn:aws:es:us-east-1:123456789012:domain/cli-example/*\"}]}", "Status": { "CreationDate": 1589395034.946, "UpdateDate": 1589395827.325, "UpdateVersion": 8, "State": "Active", "PendingDeletion": false } }, "SnapshotOptions": { "Options": { "AutomatedSnapshotStartHour": 0 }, "Status": { "CreationDate": 1589395034.946, "UpdateDate": 1589395827.325, "UpdateVersion": 8, "State": "Active", "PendingDeletion": false } }, "VPCOptions": { "Options": {}, "Status": { "CreationDate": 1591210426.162, "UpdateDate": 1591210426.162, "UpdateVersion": 18, "State": "Active", "PendingDeletion": false } }, "CognitoOptions": { "Options": { "Enabled": false }, "Status": { "CreationDate": 1591210426.163, "UpdateDate": 1591210426.163, "UpdateVersion": 18, "State": "Active", "PendingDeletion": false } }, "EncryptionAtRestOptions": { "Options": { "Enabled": true, "KmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/1a2a3a4a-1a2a-1a2a-1a2a-1a2a3a4a5a6a" }, "Status": { "CreationDate": 1589395034.946, "UpdateDate": 1589395827.325, "UpdateVersion": 8, "State": "Active", "PendingDeletion": false } }, "NodeToNodeEncryptionOptions": { "Options": { "Enabled": true }, "Status": { "CreationDate": 1589395034.946, "UpdateDate": 1589395827.325, "UpdateVersion": 8, "State": "Active", "PendingDeletion": false } }, "AdvancedOptions": { "Options": { "rest.action.multi.allow_explicit_index": "true" }, "Status": { "CreationDate": 1589395034.946, "UpdateDate": 1589395827.325, "UpdateVersion": 8, "State": "Active", "PendingDeletion": false } }, "LogPublishingOptions": { "Options": {}, "Status": { "CreationDate": 1591210426.164, "UpdateDate": 1591210426.164, "UpdateVersion": 18, "State": "Active", "PendingDeletion": false } }, "DomainEndpointOptions": { "Options": { "EnforceHTTPS": true, "TLSSecurityPolicy": "Policy-Min-TLS-1-0-2019-07" }, "Status": { "CreationDate": 1589395034.946, "UpdateDate": 1589395827.325, "UpdateVersion": 8, "State": "Active", "PendingDeletion": false } }, "AdvancedSecurityOptions": { "Options": { "Enabled": true, "InternalUserDatabaseEnabled": true }, "Status": { "CreationDate": 1589395034.946, "UpdateDate": 1589827485.577, "UpdateVersion": 14, "State": "Active", "PendingDeletion": false } } } }
For more information, see Creating and Managing Amazon Elasticsearch Service Domains in the Amazon Elasticsearch Service Developer Guide.
-
For API details, see DescribeElasticsearchDomainConfig
in AWS CLI Command Reference.
-
The following code example shows how to use describe-elasticsearch-domain
.
- AWS CLI
-
To get details for a single domain
The following
describe-elasticsearch-domain
example provides configuration details for a given domain.aws es describe-elasticsearch-domain \ --domain-name
cli-example
Output:
{ "DomainStatus": { "DomainId": "123456789012/cli-example", "DomainName": "cli-example", "ARN": "arn:aws:es:us-east-1:123456789012:domain/cli-example", "Created": true, "Deleted": false, "Endpoint": "search-cli-example-1a2a3a4a5a6a7a8a9a0a.us-east-1.es.amazonaws.com", "Processing": false, "UpgradeProcessing": false, "ElasticsearchVersion": "7.4", "ElasticsearchClusterConfig": { "InstanceType": "c5.large.elasticsearch", "InstanceCount": 1, "DedicatedMasterEnabled": true, "ZoneAwarenessEnabled": false, "DedicatedMasterType": "c5.large.elasticsearch", "DedicatedMasterCount": 3, "WarmEnabled": true, "WarmType": "ultrawarm1.medium.elasticsearch", "WarmCount": 2 }, "EBSOptions": { "EBSEnabled": true, "VolumeType": "gp2", "VolumeSize": 10 }, "AccessPolicies": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"es:*\",\"Resource\":\"arn:aws:es:us-east-1:123456789012:domain/cli-example/*\"}]}", "SnapshotOptions": { "AutomatedSnapshotStartHour": 0 }, "CognitoOptions": { "Enabled": false }, "EncryptionAtRestOptions": { "Enabled": true, "KmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/1a2a3a4a-1a2a-1a2a-1a2a-1a2a3a4a5a6a" }, "NodeToNodeEncryptionOptions": { "Enabled": true }, "AdvancedOptions": { "rest.action.multi.allow_explicit_index": "true" }, "ServiceSoftwareOptions": { "CurrentVersion": "R20200522", "NewVersion": "", "UpdateAvailable": false, "Cancellable": false, "UpdateStatus": "COMPLETED", "Description": "There is no software update available for this domain.", "AutomatedUpdateDate": 0.0 }, "DomainEndpointOptions": { "EnforceHTTPS": true, "TLSSecurityPolicy": "Policy-Min-TLS-1-0-2019-07" }, "AdvancedSecurityOptions": { "Enabled": true, "InternalUserDatabaseEnabled": true } } }
For more information, see Creating and Managing Amazon Elasticsearch Service Domains in the Amazon Elasticsearch Service Developer Guide.
-
For API details, see DescribeElasticsearchDomain
in AWS CLI Command Reference.
-
The following code example shows how to use describe-elasticsearch-domains
.
- AWS CLI
-
To get details for one or more domains
The following
describe-elasticsearch-domains
example provides configuration details for one or more domains.aws es describe-elasticsearch-domains \ --domain-names
cli-example-1
cli-example-2
Output:
{ "DomainStatusList": [{ "DomainId": "123456789012/cli-example-1", "DomainName": "cli-example-1", "ARN": "arn:aws:es:us-east-1:123456789012:domain/cli-example-1", "Created": true, "Deleted": false, "Endpoint": "search-cli-example-1-1a2a3a4a5a6a7a8a9a0a.us-east-1.es.amazonaws.com", "Processing": false, "UpgradeProcessing": false, "ElasticsearchVersion": "7.4", "ElasticsearchClusterConfig": { "InstanceType": "c5.large.elasticsearch", "InstanceCount": 1, "DedicatedMasterEnabled": true, "ZoneAwarenessEnabled": false, "DedicatedMasterType": "c5.large.elasticsearch", "DedicatedMasterCount": 3, "WarmEnabled": true, "WarmType": "ultrawarm1.medium.elasticsearch", "WarmCount": 2 }, "EBSOptions": { "EBSEnabled": true, "VolumeType": "gp2", "VolumeSize": 10 }, "AccessPolicies": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"es:*\",\"Resource\":\"arn:aws:es:us-east-1:123456789012:domain/cli-example-1/*\"}]}", "SnapshotOptions": { "AutomatedSnapshotStartHour": 0 }, "CognitoOptions": { "Enabled": false }, "EncryptionAtRestOptions": { "Enabled": true, "KmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/1a2a3a4a-1a2a-1a2a-1a2a-1a2a3a4a5a6a" }, "NodeToNodeEncryptionOptions": { "Enabled": true }, "AdvancedOptions": { "rest.action.multi.allow_explicit_index": "true" }, "ServiceSoftwareOptions": { "CurrentVersion": "R20200522", "NewVersion": "", "UpdateAvailable": false, "Cancellable": false, "UpdateStatus": "COMPLETED", "Description": "There is no software update available for this domain.", "AutomatedUpdateDate": 0.0 }, "DomainEndpointOptions": { "EnforceHTTPS": true, "TLSSecurityPolicy": "Policy-Min-TLS-1-0-2019-07" }, "AdvancedSecurityOptions": { "Enabled": true, "InternalUserDatabaseEnabled": true } }, { "DomainId": "123456789012/cli-example-2", "DomainName": "cli-example-2", "ARN": "arn:aws:es:us-east-1:123456789012:domain/cli-example-2", "Created": true, "Deleted": false, "Processing": true, "UpgradeProcessing": false, "ElasticsearchVersion": "7.4", "ElasticsearchClusterConfig": { "InstanceType": "r5.large.elasticsearch", "InstanceCount": 1, "DedicatedMasterEnabled": false, "ZoneAwarenessEnabled": false, "WarmEnabled": false }, "EBSOptions": { "EBSEnabled": true, "VolumeType": "gp2", "VolumeSize": 10 }, "AccessPolicies": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Deny\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"es:*\",\"Resource\":\"arn:aws:es:us-east-1:123456789012:domain/cli-example-2/*\"}]}", "SnapshotOptions": { "AutomatedSnapshotStartHour": 0 }, "CognitoOptions": { "Enabled": false }, "EncryptionAtRestOptions": { "Enabled": false }, "NodeToNodeEncryptionOptions": { "Enabled": false }, "AdvancedOptions": { "rest.action.multi.allow_explicit_index": "true" }, "ServiceSoftwareOptions": { "CurrentVersion": "", "NewVersion": "", "UpdateAvailable": false, "Cancellable": false, "UpdateStatus": "COMPLETED", "Description": "There is no software update available for this domain.", "AutomatedUpdateDate": 0.0 }, "DomainEndpointOptions": { "EnforceHTTPS": false, "TLSSecurityPolicy": "Policy-Min-TLS-1-0-2019-07" }, "AdvancedSecurityOptions": { "Enabled": false, "InternalUserDatabaseEnabled": false } } ] }
For more information, see Creating and Managing Amazon Elasticsearch Service Domains in the Amazon Elasticsearch Service Developer Guide.
-
For API details, see DescribeElasticsearchDomains
in AWS CLI Command Reference.
-
The following code example shows how to use describe-reserved-elasticsearch-instances
.
- AWS CLI
-
To view all reserved instances
The following
describe-elasticsearch-domains
example provides a summary of all instances you have reserved in a region.aws es describe-reserved-elasticsearch-instances
Output:
{ "ReservedElasticsearchInstances": [{ "FixedPrice": 100.0, "ReservedElasticsearchInstanceOfferingId": "1a2a3a4a5-1a2a-3a4a-5a6a-1a2a3a4a5a6a", "ReservationName": "my-reservation", "PaymentOption": "PARTIAL_UPFRONT", "UsagePrice": 0.0, "ReservedElasticsearchInstanceId": "9a8a7a6a-5a4a-3a2a-1a0a-9a8a7a6a5a4a", "RecurringCharges": [{ "RecurringChargeAmount": 0.603, "RecurringChargeFrequency": "Hourly" }], "State": "payment-pending", "StartTime": 1522872571.229, "ElasticsearchInstanceCount": 3, "Duration": 31536000, "ElasticsearchInstanceType": "m4.2xlarge.elasticsearch", "CurrencyCode": "USD" }] }
For more information, see Reserved Instances in the Amazon Elasticsearch Service Developer Guide.
-
For API details, see DescribeReservedElasticsearchInstances
in AWS CLI Command Reference.
-
The following code example shows how to use list-domain-names
.
- AWS CLI
-
To list all domains
The following
list-domain-names
example provides a quick summary of all domains in the region.aws es list-domain-names
Output:
{ "DomainNames": [{ "DomainName": "cli-example-1" }, { "DomainName": "cli-example-2" } ] }
For more information, see Creating and Managing Amazon Elasticsearch Service Domains in the Amazon Elasticsearch Service Developer Guide.
-
For API details, see ListDomainNames
in AWS CLI Command Reference.
-