

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 [AWS](https://github.com/awsdocs/aws-doc-sdk-examples)

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Tools for PowerShell V4 を使用した Amazon ECS の例
<a name="powershell_4_ecs_code_examples"></a>

次のコード例は、Amazon ECS で AWS Tools for PowerShell V4 を使用してアクションを実行し、一般的なシナリオを実装する方法を示しています。

*アクション*はより大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。アクションは個々のサービス機能を呼び出す方法を示していますが、コンテキスト内のアクションは、関連するシナリオで確認できます。

各例には完全なソースコードへのリンクが含まれており、コードの設定方法と実行方法に関する手順を確認できます。

**Topics**
+ [アクション](#actions)

## アクション
<a name="actions"></a>

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

次のコード例は、`Get-ECSClusterDetail` を使用する方法を示しています。

**Tools for PowerShell V4**  
**例 1: このコマンドレットでは、1 つ以上の ECS クラスターを記述します。**  

```
Get-ECSClusterDetail -Cluster "LAB-ECS-CL" -Include SETTINGS | Select-Object *
```
**出力:**  

```
LoggedAt         : 12/27/2019 9:27:41 PM
Clusters         : {LAB-ECS-CL}
Failures         : {}
ResponseMetadata : Amazon.Runtime.ResponseMetadata
ContentLength    : 396
HttpStatusCode   : OK
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V4)* の「[DescribeClusters](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。

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

次のコード例は、`Get-ECSClusterList` を使用する方法を示しています。

**Tools for PowerShell V4**  
**例 1: このコマンドレットは、既存の ECS クラスターのリストを返します。**  

```
Get-ECSClusterList
```
**出力:**  

```
arn:aws:ecs:us-west-2:012345678912:cluster/LAB-ECS-CL
arn:aws:ecs:us-west-2:012345678912:cluster/LAB-ECS
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V4)* の「[ListClusters](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。

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

次のコード例は、`Get-ECSClusterService` を使用する方法を示しています。

**Tools for PowerShell V4**  
**例 1: この例では、デフォルトのクラスターで実行されているすべてのサービスを一覧表示します。**  

```
Get-ECSClusterService
```
**例 2: この例では、指定されたクラスターで実行されているすべてのサービスを一覧表示します。**  

```
Get-ECSClusterService -Cluster myCluster
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V4)* の「[ListServices](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。

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

次のコード例は、`Get-ECSService` を使用する方法を示しています。

**Tools for PowerShell V4**  
**例 1: この例では、デフォルトのクラスターから特定のサービスの詳細を取得する方法を示します。**  

```
Get-ECSService -Service my-hhtp-service
```
**例 2: この例では、名前付きクラスターで実行されている特定のサービスの詳細を取得する方法を示します。**  

```
Get-ECSService -Cluster myCluster -Service my-hhtp-service
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V4)* の「[DescribeServices](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。

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

次のコード例は、`New-ECSCluster` を使用する方法を示しています。

**Tools for PowerShell V4**  
**例 1: このコマンドレットは新しい Amazon ECS クラスターを作成します。**  

```
New-ECSCluster -ClusterName "LAB-ECS-CL" -Setting @{Name="containerInsights"; Value="enabled"}
```
**出力:**  

```
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                              : {}
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V4)* の「[CreateCluster](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。

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

次のコード例は、`New-ECSService` を使用する方法を示しています。

**Tools for PowerShell V4**  
例 1: このコマンド例では、デフォルトのクラスターに「ecs-simple-service」というサービスを作成します。このサービスは `ecs-demo` タスク定義を使用し、そのタスクのインスタンスを 10 個保持します。  

```
New-ECSService -ServiceName ecs-simple-service -TaskDefinition ecs-demo -DesiredCount 10
```
例 2: このコマンド例では、デフォルトクラスター内で、ロードバランサーの背後に「ecs-simple-service」という名前のサービスを作成します。このサービスは `ecs-demo` タスク定義を使用し、そのタスクのインスタンスを 10 個保持します。  

```
$lb = @{
    LoadBalancerName = "EC2Contai-EcsElast-S06278JGSJCM"
    ContainerName = "simple-demo"
    ContainerPort = 80
}        
New-ECSService -ServiceName ecs-simple-service -TaskDefinition ecs-demo -DesiredCount 10 -LoadBalancer $lb
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V4)* の「[CreateService](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。

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

次のコード例は、`Remove-ECSCluster` を使用する方法を示しています。

**Tools for PowerShell V4**  
**例 1: このコマンドレットは、指定された ECS クラスターを削除します。削除する前に、このクラスターからすべてのコンテナインスタンスを登録解除する必要があります。**  

```
Remove-ECSCluster -Cluster "LAB-ECS"
```
**出力:**  

```
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
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V4)* の「[DeleteCluster](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。

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

次のコード例は、`Remove-ECSService` を使用する方法を示しています。

**Tools for PowerShell V4**  
**例 1: デフォルトクラスターで「my-http-service」という名前のサービスを削除します。サービスを削除する前に、必要数と実行中の数が 0 である必要があります。コマンドを続行する前に確認を求められます。確認を省略するには、-Force スイッチを追加します。**  

```
Remove-ECSService -Service my-http-service
```
**例 2: 名前付きクラスターで「my-http-service」という名前のサービスを削除します。**  

```
Remove-ECSService -Cluster myCluster -Service my-http-service
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V4)* の「[DeleteService](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。

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

次のコード例は、`Update-ECSClusterSetting` を使用する方法を示しています。

**Tools for PowerShell V4**  
**例 1: このコマンドレットは、ECS クラスターに使用する設定を変更します。**  

```
Update-ECSClusterSetting -Cluster "LAB-ECS-CL" -Setting @{Name="containerInsights"; Value="disabled"}
```
**出力:**  

```
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                              : {}
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V4)* の「[UpdateClusterSettings](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。

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

次のコード例は、`Update-ECSService` を使用する方法を示しています。

**Tools for PowerShell V4**  
**例 1: このコマンド例では、「my-http-service」サービスを更新して「amazon-ecs-sample」タスク定義を使用します**  

```
Update-ECSService -Service my-http-service -TaskDefinition amazon-ecs-sample
```
**例 2: このコマンド例では、`my-http-service` サービスの必要数を 10 に更新します。**  

```
Update-ECSService -Service my-http-service -DesiredCount 10
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V4)* の「[UpdateService](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。