View a markdown version of this page

使用适用于 PowerShell V4 的工具的 Amazon ECS 示例 - Amazon Tools for PowerShell (版本 4)
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

Amazon Tools for PowerShell V4 的支持已到期。

我们建议您迁移到 Amazon Tools for PowerShell V5 。有关如何迁移的更多详细信息和信息,请参阅我们的终止支持公告

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用适用于 PowerShell V4 的工具的 Amazon ECS 示例

以下代码示例向您展示了如何使用带有 Amazon ECS 的 Amazon Tools for PowerShell V4 来执行操作和实现常见场景。

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示了如何使用 Get-ECSClusterDetail

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 描述一个或多个 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 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) DescribeClusters中的。

以下代码示例演示了如何使用 Get-ECSClusterList

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 返回现有 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 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) ListClusters中的。

以下代码示例演示了如何使用 Get-ECSClusterService

适用于 PowerShell V4 的工具

示例 1:此示例列出在默认集群中运行的所有服务。

Get-ECSClusterService

示例 2:此示例列出在指定集群中运行的所有服务。

Get-ECSClusterService -Cluster myCluster
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) ListServices中的。

以下代码示例演示了如何使用 Get-ECSService

适用于 PowerShell V4 的工具

示例 1:此示例演示如何从默认集群中检索特定服务的详细信息。

Get-ECSService -Service my-hhtp-service

示例 2:此示例演示如何检索在指定集群中运行的特定服务的详细信息。

Get-ECSService -Cluster myCluster -Service my-hhtp-service
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) DescribeServices中的。

以下代码示例演示了如何使用 New-ECSCluster

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 创建一个新的 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 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) CreateCluster中的。

以下代码示例演示了如何使用 New-ECSService

适用于 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 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) CreateService中的。

以下代码示例演示了如何使用 Remove-ECSCluster

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 删除指定的 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 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) DeleteCluster中的。

以下代码示例演示了如何使用 Remove-ECSService

适用于 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 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) DeleteService中的。

以下代码示例演示了如何使用 Update-ECSClusterSetting

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 修改要用于 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 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) UpdateClusterSettings中的。

以下代码示例演示了如何使用 Update-ECSService

适用于 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 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) UpdateService中的。