OpenSearch Contoh layanan menggunakan AWS CLI - AWS Command Line Interface

Dokumentasi ini AWS CLI hanya untuk Versi 1. Untuk dokumentasi yang terkait dengan Versi 2 AWS CLI, lihat Panduan Pengguna Versi 2.

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

OpenSearch Contoh layanan menggunakan AWS CLI

Contoh kode berikut menunjukkan kepada Anda cara melakukan tindakan dan mengimplementasikan skenario umum dengan menggunakan OpenSearch Layanan AWS Command Line Interface with.

Tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Sementara tindakan menunjukkan cara memanggil fungsi layanan individual, Anda dapat melihat tindakan dalam konteks dalam skenario terkait.

Setiap contoh menyertakan tautan ke kode sumber lengkap, di mana Anda dapat menemukan instruksi tentang cara mengatur dan menjalankan kode dalam konteks.

Tindakan

Contoh kode berikut menunjukkan cara menggunakancreate-elasticsearch-domain.

AWS CLI

Untuk membuat domain Amazon Elasticsearch Service

create-elasticsearch-domainPerintah berikut membuat domain Amazon Elasticsearch Service baru dalam VPC dan membatasi akses ke satu pengguna. Amazon ES menyimpulkan VPC ID dari subnet dan grup keamanan yang ditentukan. IDs

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

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

Untuk informasi selengkapnya, lihat Membuat dan Mengelola Domain Layanan Amazon Elasticsearch di Panduan Pengembang Amazon Elasticsearch Service.

Contoh kode berikut menunjukkan cara menggunakandescribe-elasticsearch-domain-config.

AWS CLI

Untuk mendapatkan detail konfigurasi domain

describe-elasticsearch-domain-configContoh berikut memberikan rincian konfigurasi untuk domain tertentu, bersama dengan informasi status untuk setiap komponen domain individu.

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

Untuk informasi selengkapnya, lihat Membuat dan Mengelola Domain Layanan Amazon Elasticsearch di Panduan Pengembang Amazon Elasticsearch Service.

Contoh kode berikut menunjukkan cara menggunakandescribe-elasticsearch-domain.

AWS CLI

Untuk mendapatkan detail untuk satu domain

describe-elasticsearch-domainContoh berikut memberikan rincian konfigurasi untuk domain tertentu.

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

Untuk informasi selengkapnya, lihat Membuat dan Mengelola Domain Layanan Amazon Elasticsearch di Panduan Pengembang Amazon Elasticsearch Service.

Contoh kode berikut menunjukkan cara menggunakandescribe-elasticsearch-domains.

AWS CLI

Untuk mendapatkan detail untuk satu atau beberapa domain

describe-elasticsearch-domainsContoh berikut memberikan rincian konfigurasi untuk satu atau beberapa domain.

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

Untuk informasi selengkapnya, lihat Membuat dan Mengelola Domain Layanan Amazon Elasticsearch di Panduan Pengembang Amazon Elasticsearch Service.

Contoh kode berikut menunjukkan cara menggunakandescribe-reserved-elasticsearch-instances.

AWS CLI

Untuk melihat semua instance yang dicadangkan

describe-elasticsearch-domainsContoh berikut memberikan ringkasan semua instance yang telah Anda pesan di suatu wilayah.

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

Untuk informasi selengkapnya, lihat Instans Cadangan di Panduan Pengembang Amazon Elasticsearch Service.

Contoh kode berikut menunjukkan cara menggunakanlist-domain-names.

AWS CLI

Untuk daftar semua domain

list-domain-namesContoh berikut memberikan ringkasan singkat dari semua domain di wilayah tersebut.

aws es list-domain-names

Output:

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

Untuk informasi selengkapnya, lihat Membuat dan Mengelola Domain Layanan Amazon Elasticsearch di Panduan Pengembang Amazon Elasticsearch Service.