如何为使用计划任务且无服务的ECS集群设置自动伸缩?

How to set up autoscaling for ECS cluster that uses scheduled tasks and no service?

我有一个 ECS 集群,我绑定了一个 ec2 实例,并使用 ECS 仪表板上的 'Scheduled Tasks' 功能将计划任务设置为每天 运行。

此任务 运行 是一堆容器,每个容器的内存都相对昂贵,并且一次 运行ning 所有容器更是如此。

我目前没有为 ECS 集群设置服务,据我了解,为了我的目标,运行在某个时间间隔设置任务,不会使用服务。

AWS 在 ECS 文档中对服务的定义说:

An Amazon ECS service enables you to run and maintain a specified number of instances of a task definition simultaneously in an Amazon ECS cluster.

因为这不是我想要的;相反,我只需要 运行 在我收集到的某个预定时间间隔执行任务 我不需要与我的 ECS 集群相关联的服务。

我的问题是如何为我的计划任务设置自动缩放?我能找到的关于在 ECS 集群中自动缩放的唯一参考是创建自动缩放的 ecs 服务——这又不是我想要的(至少从我理解 ecs 服务的工作方式来看)。

我需要的是让我的 ec2 实例随着我的计划任务 运行 自动扩展,根据任务需要分配更多资源给 运行。我是否只需要在 ec2 仪表板中绑定 ecs 集群的特定 ec2 实例上设置自动缩放,还是有其他方法可以直接从 ECS 执行此操作?

I want; instead, I need to just run a task on some scheduled interval I gather I do not need a service tied to my ECS cluster.

对于上述用例,最好使用 fargate你不会维护或担心自动缩放调度,你只需要设置计划任务,AWS 将处理您的任务所需的内存和其他资源,而且您只需为您的 ECS 任务使用的资源付费,这与您在其中执行的 EC2 类型任务不同为容器实例付费。

AWS Fargate is a serverless compute engine for containers that works with both Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS). Fargate makes it easy for you to focus on building your applications. Fargate removes the need to provision and manage servers, lets you specify and pay for resources per application, and improves security through application isolation by design.

aws fargate

根据一些触发任务的计划创建云监视规则,确保容器在完成作业后退出,fargate 将自动停止容器。

cloudwatch-event-rule-to-invoke-an-ecs-task