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 Answer
1
Accepted Answer

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
EXPERT
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions