OpenSearch 使用的服务示例 Amazon CLI - Amazon Command Line Interface
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

OpenSearch 使用的服务示例 Amazon CLI

以下代码示例向您展示了如何使用 with S OpenSearch ervice 来执行操作和实现常见场景。 Amazon Command Line Interface

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。

每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 create-elasticsearch-domain

Amazon CLI

创建 Amazon Elasticsearch Service 域名

以下create-elasticsearch-domain命令在 VPC 内创建一个新的 Amazon Elasticsearch Service 域并限制单个用户的访问权限。Amazon ES 根据指定的子网和安全组 ID 推断出 VPC ID。

aws es create-elasticsearch-domain \ --domain-name vpc-cli-example \ --elasticsearch-version 6.2 \ --elasticsearch-cluster-config InstanceType=m4.large.elasticsearch,InstanceCount=1 \ --ebs-options EBSEnabled=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-options SubnetIds=subnet-1a2a3a4a,SecurityGroupIds=sg-2a3a4a5a

输出:

{ "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" } }

有关更多信息,请参阅亚马逊 Elasticsearch Service 开发者指南中的创建和管理亚马逊 Elasticsearch 服务

以下代码示例演示如何使用 describe-elasticsearch-domain-config

Amazon CLI

获取域配置详细信息

以下describe-elasticsearch-domain-config示例提供了给定域的配置详细信息以及每个域组件的状态信息。

aws es describe-elasticsearch-domain-config \ --domain-name cli-example

输出:

{ "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 } } } }

有关更多信息,请参阅亚马逊 Elasticsearch Service 开发者指南中的创建和管理亚马逊 Elasticsearch 服务

以下代码示例演示如何使用 describe-elasticsearch-domain

Amazon CLI

获取单个域名的详细信息

以下describe-elasticsearch-domain示例提供了给定域的配置详细信息。

aws es describe-elasticsearch-domain \ --domain-name cli-example

输出:

{ "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 } } }

有关更多信息,请参阅亚马逊 Elasticsearch Service 开发者指南中的创建和管理亚马逊 Elasticsearch 服务

以下代码示例演示如何使用 describe-elasticsearch-domains

Amazon CLI

获取一个或多个域名的详细信息

以下describe-elasticsearch-domains示例提供了一个或多个域的配置详细信息。

aws es describe-elasticsearch-domains \ --domain-names cli-example-1 cli-example-2

输出:

{ "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 } } ] }

有关更多信息,请参阅亚马逊 Elasticsearch Service 开发者指南中的创建和管理亚马逊 Elasticsearch 服务

以下代码示例演示如何使用 describe-reserved-elasticsearch-instances

Amazon CLI

查看所有预留实例

以下describe-elasticsearch-domains示例汇总了您在某个地区预留的所有实例。

aws es describe-reserved-elasticsearch-instances

输出:

{ "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" }] }

有关更多信息,请参阅 Amazon Elasticsearch Servic e 开发者指南中的预留实例

以下代码示例演示如何使用 list-domain-names

Amazon CLI

列出所有域名

以下list-domain-names示例提供了该地区所有域名的快速摘要。

aws es list-domain-names

输出:

{ "DomainNames": [{ "DomainName": "cli-example-1" }, { "DomainName": "cli-example-2" } ] }

有关更多信息,请参阅亚马逊 Elasticsearch Service 开发者指南中的创建和管理亚马逊 Elasticsearch 服务

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListDomainNames中的。