文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 的 OpenSearch Service 範例 AWS CLI
下列程式碼範例示範如何使用 AWS Command Line Interface with OpenSearch Service 來執行動作和實作常見案例。
Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然 動作會示範如何呼叫個別服務函數,但您可以在其相關案例中查看內容中的動作。
每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。
主題
動作
下列程式碼範例示範如何使用 create-elasticsearch-domain
。
- AWS CLI
-
若要建立 Amazon Elasticsearch Service 網域
下列
create-elasticsearch-domain
命令會在 VPC 中建立新的 Amazon Elasticsearch Service 網域,並限制單一使用者的存取。Amazon ES 從指定的子網路和安全群組 VPC 推斷 IDs ID。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
輸出:
{ "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" } }
如需詳細資訊,請參閱 Amazon Elasticsearch Service 開發人員指南中的建立和管理 Amazon Elasticsearch Service 網域。 Amazon Elasticsearch Service
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateElasticsearchDomain
。
-
下列程式碼範例示範如何使用 describe-elasticsearch-domain-config
。
- AWS 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 } } } }
如需詳細資訊,請參閱 Amazon Elasticsearch Service 開發人員指南中的建立和管理 Amazon Elasticsearch Service 網域。 Amazon Elasticsearch Service
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeElasticsearchDomainConfig
。
-
下列程式碼範例示範如何使用 describe-elasticsearch-domain
。
- AWS 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 } } }
如需詳細資訊,請參閱 Amazon Elasticsearch Service 開發人員指南中的建立和管理 Amazon Elasticsearch Service 網域。 Amazon Elasticsearch Service
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeElasticsearchDomain
。
-
下列程式碼範例示範如何使用 describe-elasticsearch-domains
。
- AWS 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 } } ] }
如需詳細資訊,請參閱 Amazon Elasticsearch Service 開發人員指南中的建立和管理 Amazon Elasticsearch Service 網域。 Amazon Elasticsearch Service
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeElasticsearchDomains
。
-
下列程式碼範例示範如何使用 describe-reserved-elasticsearch-instances
。
- AWS 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 Service 開發人員指南中的預留執行個體。
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeReservedElasticsearchInstances
。
-
下列程式碼範例示範如何使用 list-domain-names
。
- AWS CLI
-
列出所有網域
下列
list-domain-names
範例提供 區域中所有網域的快速摘要。aws es list-domain-names
輸出:
{ "DomainNames": [{ "DomainName": "cli-example-1" }, { "DomainName": "cli-example-2" } ] }
如需詳細資訊,請參閱 Amazon Elasticsearch Service 開發人員指南中的建立和管理 Amazon Elasticsearch Service 網域。 Amazon Elasticsearch Service
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 ListDomainNames
。
-