Ada lebih banyak contoh AWS SDK yang tersedia di repo Contoh SDK AWS Doc
Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Gunakan DescribeClusters
dengan AWS SDK atau CLI
Contoh kode berikut menunjukkan cara menggunakanDescribeClusters
.
- CLI
-
- AWS CLI
-
Contoh 1: Untuk mendeskripsikan sebuah cluster
describe-clusters
Contoh berikut mengambil rincian tentang cluster tertentu.aws ecs describe-clusters \ --cluster
default
Output:
{ "clusters": [ { "status": "ACTIVE", "clusterName": "default", "registeredContainerInstancesCount": 0, "pendingTasksCount": 0, "runningTasksCount": 0, "activeServicesCount": 1, "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/default" } ], "failures": [] }
Untuk informasi selengkapnya, lihat Cluster Amazon ECS di Panduan Pengembang Amazon ECS.
Contoh 2: Untuk mendeskripsikan cluster dengan opsi lampiran
describe-clusters
Contoh berikut menentukan pilihan ATTACHMENTS. Ini mengambil rincian tentang cluster yang ditentukan dan daftar sumber daya yang melekat pada cluster dalam bentuk lampiran. Saat menggunakan penyedia kapasitas dengan klaster, sumber daya, baik AutoScaling rencana atau kebijakan penskalaan, akan direpresentasikan sebagai asp atau as_policy ATTACHMENTS.aws ecs describe-clusters \ --include
ATTACHMENTS
\ --clusterssampleCluster
Output:
{ "clusters": [ { "clusterArn": "arn:aws:ecs:af-south-1:123456789222:cluster/sampleCluster", "clusterName": "sampleCluster", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "runningTasksCount": 0, "pendingTasksCount": 0, "activeServicesCount": 0, "statistics": [], "tags": [], "settings": [], "capacityProviders": [ "sampleCapacityProvider" ], "defaultCapacityProviderStrategy": [], "attachments": [ { "id": "a1b2c3d4-5678-901b-cdef-EXAMPLE22222", "type": "as_policy", "status": "CREATED", "details": [ { "name": "capacityProviderName", "value": "sampleCapacityProvider" }, { "name": "scalingPolicyName", "value": "ECSManagedAutoScalingPolicy-3048e262-fe39-4eaf-826d-6f975d303188" } ] } ], "attachmentsStatus": "UPDATE_COMPLETE" } ], "failures": [] }
Untuk informasi selengkapnya, lihat Cluster Amazon ECS di Panduan Pengembang Amazon ECS.
-
Untuk detail API, lihat DescribeClusters
di Referensi AWS CLI Perintah.
-
- Java
-
- SDK untuk Java 2.x
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.ecs.EcsClient; import software.amazon.awssdk.services.ecs.model.DescribeClustersRequest; import software.amazon.awssdk.services.ecs.model.DescribeClustersResponse; import software.amazon.awssdk.services.ecs.model.Cluster; import software.amazon.awssdk.services.ecs.model.EcsException; import java.util.List; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class DescribeClusters { public static void main(String[] args) { final String usage = """ Usage: <clusterArn> \s Where: clusterArn - The ARN of the ECS cluster to describe. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String clusterArn = args[0]; Region region = Region.US_EAST_1; EcsClient ecsClient = EcsClient.builder() .region(region) .build(); descCluster(ecsClient, clusterArn); } public static void descCluster(EcsClient ecsClient, String clusterArn) { try { DescribeClustersRequest clustersRequest = DescribeClustersRequest.builder() .clusters(clusterArn) .build(); DescribeClustersResponse response = ecsClient.describeClusters(clustersRequest); List<Cluster> clusters = response.clusters(); for (Cluster cluster : clusters) { System.out.println("The cluster name is " + cluster.clusterName()); } } catch (EcsException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
-
Untuk detail API, lihat DescribeClustersdi Referensi AWS SDK for Java 2.x API.
-
- PowerShell
-
- Alat untuk PowerShell
-
Contoh 1: Cmdlet ini menjelaskan satu atau lebih cluster ECS Anda.
Get-ECSClusterDetail -Cluster "LAB-ECS-CL" -Include SETTINGS | Select-Object *
Output:
LoggedAt : 12/27/2019 9:27:41 PM Clusters : {LAB-ECS-CL} Failures : {} ResponseMetadata : Amazon.Runtime.ResponseMetadata ContentLength : 396 HttpStatusCode : OK
-
Untuk detail API, lihat DescribeClustersdi Referensi Alat AWS untuk PowerShell Cmdlet.
-
- Rust
-
- SDK untuk Rust
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. async fn show_clusters(client: &aws_sdk_ecs::Client) -> Result<(), aws_sdk_ecs::Error> { let resp = client.list_clusters().send().await?; let cluster_arns = resp.cluster_arns(); println!("Found {} clusters:", cluster_arns.len()); let clusters = client .describe_clusters() .set_clusters(Some(cluster_arns.into())) .send() .await?; for cluster in clusters.clusters() { println!(" ARN: {}", cluster.cluster_arn().unwrap()); println!(" Name: {}", cluster.cluster_name().unwrap()); } Ok(()) }
-
Untuk detail API, lihat DescribeClusters
referensi AWS SDK for Rust API.
-