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 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南