View a markdown version of this page

Contoh Amazon ECS menggunakan Alat untuk V5 PowerShell - Alat AWS untuk PowerShell (versi 5)

Versi 5 (V5) Alat AWS untuk PowerShell telah dirilis!

Untuk informasi tentang mengubah perubahan dan memigrasikan aplikasi Anda, lihat topik https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html migrasi.

Orange button with text "Click here for details".

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

Contoh Amazon ECS menggunakan Alat untuk V5 PowerShell

Contoh kode berikut menunjukkan cara melakukan tindakan dan menerapkan skenario umum dengan menggunakan Alat AWS untuk PowerShell V5 dengan Amazon ECS.

Tindakan merupakan 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 menggunakanGet-ECSClusterDetail.

Alat untuk PowerShell V5

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 DescribeClusters di Referensi Alat AWS untuk PowerShell Cmdlet (V5).

Contoh kode berikut menunjukkan cara menggunakanGet-ECSClusterList.

Alat untuk PowerShell V5

Contoh 1: Cmdlet ini mengembalikan daftar cluster ECS yang ada.

Get-ECSClusterList

Output:

arn:aws:ecs:us-west-2:012345678912:cluster/LAB-ECS-CL arn:aws:ecs:us-west-2:012345678912:cluster/LAB-ECS
  • Untuk detail API, lihat ListClusters di Referensi Alat AWS untuk PowerShell Cmdlet (V5).

Contoh kode berikut menunjukkan cara menggunakanGet-ECSClusterService.

Alat untuk PowerShell V5

Contoh 1: Contoh ini mencantumkan semua layanan yang berjalan di cluster default Anda.

Get-ECSClusterService

Contoh 2: Contoh ini mencantumkan semua layanan yang berjalan di cluster yang ditentukan.

Get-ECSClusterService -Cluster myCluster
  • Untuk detail API, lihat ListServices di Referensi Alat AWS untuk PowerShell Cmdlet (V5).

Contoh kode berikut menunjukkan cara menggunakanGet-ECSService.

Alat untuk PowerShell V5

Contoh 1: Contoh ini menunjukkan cara mengambil detail layanan tertentu dari cluster default Anda.

Get-ECSService -Service my-hhtp-service

Contoh 2: Contoh ini menunjukkan cara mengambil rincian layanan tertentu yang berjalan di cluster bernama.

Get-ECSService -Cluster myCluster -Service my-hhtp-service
  • Untuk detail API, lihat DescribeServices di Referensi Alat AWS untuk PowerShell Cmdlet (V5).

Contoh kode berikut menunjukkan cara menggunakanNew-ECSCluster.

Alat untuk PowerShell V5

Contoh 1: Cmdlet ini membuat cluster Amazon ECS baru.

New-ECSCluster -ClusterName "LAB-ECS-CL" -Setting @{Name="containerInsights"; Value="enabled"}

Output:

ActiveServicesCount : 0 Attachments : {} AttachmentsStatus : CapacityProviders : {} ClusterArn : arn:aws:ecs:us-west-2:012345678912:cluster/LAB-ECS-CL ClusterName : LAB-ECS-CL DefaultCapacityProviderStrategy : {} PendingTasksCount : 0 RegisteredContainerInstancesCount : 0 RunningTasksCount : 0 Settings : {containerInsights} Statistics : {} Status : ACTIVE Tags : {}
  • Untuk detail API, lihat CreateCluster di Referensi Alat AWS untuk PowerShell Cmdlet (V5).

Contoh kode berikut menunjukkan cara menggunakanNew-ECSService.

Alat untuk PowerShell V5

Contoh 1: Perintah contoh ini membuat layanan di cluster default Anda yang disebut `ecs-simple-service`. Layanan menggunakan definisi tugas `ecs-demo` dan mempertahankan 10 instansiasi tugas itu.

New-ECSService -ServiceName ecs-simple-service -TaskDefinition ecs-demo -DesiredCount 10

Contoh 2: Perintah contoh ini membuat layanan di belakang penyeimbang beban di cluster default Anda yang disebut `ecs-simple-service`. Layanan menggunakan definisi tugas `ecs-demo` dan mempertahankan 10 instansiasi tugas itu.

$lb = @{ LoadBalancerName = "EC2Contai-EcsElast-S06278JGSJCM" ContainerName = "simple-demo" ContainerPort = 80 } New-ECSService -ServiceName ecs-simple-service -TaskDefinition ecs-demo -DesiredCount 10 -LoadBalancer $lb
  • Untuk detail API, lihat CreateService di Referensi Alat AWS untuk PowerShell Cmdlet (V5).

Contoh kode berikut menunjukkan cara menggunakanRemove-ECSCluster.

Alat untuk PowerShell V5

Contoh 1: Cmdlet ini menghapus cluster ECS yang ditentukan. Anda harus membatalkan pendaftaran semua instance kontainer dari cluster ini sebelum Anda dapat menghapusnya.

Remove-ECSCluster -Cluster "LAB-ECS"

Output:

Confirm Are you sure you want to perform this action? Performing the operation "Remove-ECSCluster (DeleteCluster)" on target "LAB-ECS". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y
  • Untuk detail API, lihat DeleteCluster di Referensi Alat AWS untuk PowerShell Cmdlet (V5).

Contoh kode berikut menunjukkan cara menggunakanRemove-ECSService.

Alat untuk PowerShell V5

Contoh 1: Menghapus layanan bernama 'my-http-service' di cluster default. Layanan harus memiliki jumlah yang diinginkan dan hitungan berjalan 0 sebelum Anda dapat menghapusnya. Anda akan diminta untuk konfirmasi sebelum perintah dilanjutkan. Untuk melewati prompt konfirmasi tambahkan sakelar -Force.

Remove-ECSService -Service my-http-service

Contoh 2: Menghapus layanan bernama 'my-http-service' di cluster bernama.

Remove-ECSService -Cluster myCluster -Service my-http-service
  • Untuk detail API, lihat DeleteService di Referensi Alat AWS untuk PowerShell Cmdlet (V5).

Contoh kode berikut menunjukkan cara menggunakanUpdate-ECSClusterSetting.

Alat untuk PowerShell V5

Contoh 1: Cmdlet ini memodifikasi pengaturan yang akan digunakan untuk cluster ECS.

Update-ECSClusterSetting -Cluster "LAB-ECS-CL" -Setting @{Name="containerInsights"; Value="disabled"}

Output:

ActiveServicesCount : 0 Attachments : {} AttachmentsStatus : CapacityProviders : {} ClusterArn : arn:aws:ecs:us-west-2:012345678912:cluster/LAB-ECS-CL ClusterName : LAB-ECS-CL DefaultCapacityProviderStrategy : {} PendingTasksCount : 0 RegisteredContainerInstancesCount : 0 RunningTasksCount : 0 Settings : {containerInsights} Statistics : {} Status : ACTIVE Tags : {}

Contoh kode berikut menunjukkan cara menggunakanUpdate-ECSService.

Alat untuk PowerShell V5

Contoh 1: Perintah contoh ini memperbarui layanan `my-http-service` untuk menggunakan definisi tugas `amazon-ecs-sample`.

Update-ECSService -Service my-http-service -TaskDefinition amazon-ecs-sample

Contoh 2: Perintah contoh ini memperbarui jumlah yang diinginkan dari layanan `my-http-service` menjadi 10.

Update-ECSService -Service my-http-service -DesiredCount 10
  • Untuk detail API, lihat UpdateService di Referensi Alat AWS untuk PowerShell Cmdlet (V5).