By using Cloudformation, is it possible to create Task directly under ECS Cluster?

0

I am trying to create a Task in AWS ECS that does not belong to a service. In other word, I am trying to create a Task directly under Cluster. In the AWS Console, this can be done from [ECS Cluster Page]->Task Tab->Create Task or by selecting "Application Type" as "Task" from [ECS Cluster Page]->Create Service. The created task will be displayed directly in the Task Tab of the Cluster Page, and the "Task Group" value of the Task will be displayed as "family:abcde..." (not "service:abcde...").

How can I do something equivalent to this using Cloudformation? I created a Stack like the one below using AWS::ECS::Service, but the Service and Task were created at the same time. I also couldn't find a property setting of AWS::ECS::Service equivalent to Application Type: Task in the AWS Console.

AWSTemplateFormatVersion: 2010-09-09
Resources:
  ECSTaskDefinition:
    Type: 'AWS::ECS::TaskDefinition'
    Properties:
      ...
  ECSService:
    Type: 'AWS::ECS::Service'
    Properties:
      ServiceName: test-service
      Cluster: test-cluster
      DesiredCount: 1
      CapacityProviderStrategy:
        - Base: 0
          Weight: 1
          CapacityProvider: FARGATE_SPOT
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: ENABLED
          SecurityGroups:
            - ...
          Subnets:
            - ...
      TaskDefinition: !Ref ECSTaskDefinition
1 回答
1
已接受的回答

Hello.

You cannot run ECS Run Tasks using CloudFormation alone.
If you do this, I think you will need to create a custom resource with CloudFormation and execute boto3's "run_task" etc. from Lambda.

Custom resources

profile picture
专家
已回答 6 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容