

Ada lebih banyak contoh AWS SDK yang tersedia di repo Contoh [SDK AWS Doc](https://github.com/awsdocs/aws-doc-sdk-examples). GitHub 

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 PowerShell V4
<a name="powershell_4_ecs_code_examples"></a>

Contoh kode berikut menunjukkan cara melakukan tindakan dan menerapkan skenario umum dengan menggunakan Alat AWS untuk PowerShell V4 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.

**Topics**
+ [Tindakan](#actions)

## Tindakan
<a name="actions"></a>

### `Get-ECSClusterDetail`
<a name="ecs_DescribeClusters_powershell_4_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`Get-ECSClusterDetail`.

**Alat untuk PowerShell V4**  
**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](https://docs.aws.amazon.com/powershell/v4/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V4)*. 

### `Get-ECSClusterList`
<a name="ecs_ListClusters_powershell_4_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`Get-ECSClusterList`.

**Alat untuk PowerShell V4**  
**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](https://docs.aws.amazon.com/powershell/v4/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V4)*. 

### `Get-ECSClusterService`
<a name="ecs_ListServices_powershell_4_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`Get-ECSClusterService`.

**Alat untuk PowerShell V4**  
**Contoh 1: Contoh ini mencantumkan semua layanan yang berjalan di klaster default Anda.**  

```
Get-ECSClusterService
```
**Contoh 2: Contoh ini mencantumkan semua layanan yang berjalan di cluster tertentu.**  

```
Get-ECSClusterService -Cluster myCluster
```
+  Untuk detail API, lihat [ListServices](https://docs.aws.amazon.com/powershell/v4/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V4)*. 

### `Get-ECSService`
<a name="ecs_DescribeServices_powershell_4_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`Get-ECSService`.

**Alat untuk PowerShell V4**  
**Contoh 1: Contoh ini menunjukkan cara mengambil detail layanan tertentu dari klaster 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](https://docs.aws.amazon.com/powershell/v4/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V4)*. 

### `New-ECSCluster`
<a name="ecs_CreateCluster_powershell_4_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`New-ECSCluster`.

**Alat untuk PowerShell V4**  
**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](https://docs.aws.amazon.com/powershell/v4/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V4)*. 

### `New-ECSService`
<a name="ecs_CreateService_powershell_4_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`New-ECSService`.

**Alat untuk PowerShell V4**  
**Contoh 1: Perintah contoh ini membuat layanan di cluster default Anda yang disebut `ecs-simple-service`. Layanan ini menggunakan definisi tugas `ecs-demo` dan mempertahankan 10 instantiasi 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 ini menggunakan definisi tugas `ecs-demo` dan mempertahankan 10 instantiasi 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](https://docs.aws.amazon.com/powershell/v4/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V4)*. 

### `Remove-ECSCluster`
<a name="ecs_DeleteCluster_powershell_4_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`Remove-ECSCluster`.

**Alat untuk PowerShell V4**  
**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](https://docs.aws.amazon.com/powershell/v4/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V4)*. 

### `Remove-ECSService`
<a name="ecs_DeleteService_powershell_4_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`Remove-ECSService`.

**Alat untuk PowerShell V4**  
**Contoh 1: Menghapus layanan bernama 'my-http-service' di cluster default. Layanan harus memiliki hitungan yang diinginkan dan menjalankan hitungan 0 sebelum Anda dapat menghapusnya. Anda 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](https://docs.aws.amazon.com/powershell/v4/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V4)*. 

### `Update-ECSClusterSetting`
<a name="ecs_UpdateClusterSettings_powershell_4_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`Update-ECSClusterSetting`.

**Alat untuk PowerShell V4**  
**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                              : {}
```
+  Untuk detail API, lihat [UpdateClusterSettings](https://docs.aws.amazon.com/powershell/v4/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V4)*. 

### `Update-ECSService`
<a name="ecs_UpdateService_powershell_4_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`Update-ECSService`.

**Alat untuk PowerShell V4**  
**Contoh 1: Perintah contoh ini memperbarui layanan my-http-service `untuk menggunakan definisi tugasamazon-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 `` ke 10.**  

```
Update-ECSService -Service my-http-service -DesiredCount 10
```
+  Untuk detail API, lihat [UpdateService](https://docs.aws.amazon.com/powershell/v4/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V4)*. 