Deploying a docker image on ECS using FARGATE instance

0

We have created CloudFormation template to deploy the docker image which we pushed to ECR private repo. But while creating the stack, after uploading template it;s throwing an error saying : Template format error: Unresolved resource dependencies [TargetGroup, Listener] in the Resources block of the template. Can you please check my template and provide me the solution.

AWSTemplateFormatVersion: 2010-09-09 Description: CloudFormation template for deploying an app using Fargate with EBS storage.

Parameters: VPC: Type: AWS::EC2::VPC::Id # Default: vpc-0e7fa5b1456919151 Default: vpc-017326a9bde693167 SubnetA: Type: AWS::EC2::Subnet::Id # Default: subnet-0468bc81339a8e324 Default: subnet-0a5b2db7ade0b984c SubnetB: Type: AWS::EC2::Subnet::Id Default: subnet-03768793cf205ee4d SecurityGroup: Type: AWS::EC2::SecurityGroup::Id Default: sg-0f847124ae6322c82 Image: Type: String Default: public.ecr.aws/x2k3c8w4/munlq:v1 ServiceName: Type: String Default: MyService ContainerPort: Type: Number Default: 8080

Resources: Cluster: Type: AWS::ECS::Cluster Properties: ClusterName: !Join ['', [!Ref ServiceName, Cluster]]

TaskDefinition: Type: AWS::ECS::TaskDefinition Properties: NetworkMode: awsvpc RequiresCompatibilities: - FARGATE Cpu: '4096' Memory: '16384'

  ExecutionRoleArn: !GetAtt ExecutionRole.Arn
  TaskRoleArn: !GetAtt TaskRole.Arn
  ContainerDefinitions:
    - Name: !Ref ServiceName
      Image: !Ref Image
      PortMappings:
        - ContainerPort: !Ref ContainerPort
      Essential: true
  EphemeralStorage:
    SizeInGiB: 150

ExecutionRole: Type: AWS::IAM::Role Properties: RoleName: !Join ['', [!Ref ServiceName, ExecutionRole]] AssumeRolePolicyDocument: Statement: - Effect: Allow Principal: Service: ecs-tasks.amazonaws.com Action: 'sts:AssumeRole' ManagedPolicyArns: - 'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy'

TaskRole: Type: AWS::IAM::Role Properties: RoleName: !Join ['', [!Ref ServiceName, TaskRole]] AssumeRolePolicyDocument: Statement: - Effect: Allow Principal: Service: ecs-tasks.amazonaws.com Action: 'sts:AssumeRole'

FargateService: Type: AWS::ECS::Service DependsOn: Listener Properties: Cluster: !Ref Cluster LaunchType: FARGATE LoadBalancers: - TargetGroupArn: !Ref TargetGroup ContainerPort: 8080 ContainerName: test ServiceName: munlq-service DesiredCount: 1 TaskDefinition: !Ref TaskDefinition NetworkConfiguration: AwsvpcConfiguration: AssignPublicIp: ENABLED SecurityGroups: - !Ref SecurityGroup Subnets: - !Ref SubnetA - !Ref SubnetB DeploymentConfiguration: MaximumPercent: 200 MinimumHealthyPercent: 100 DeploymentCircuitBreaker: Enable: true Rollback: true

1개 답변
1
수락된 답변

Hello Only a part of your template is showing up properly and with YAML indentation is a bit of a pain when not copy-pasted properly. If you are just starting with AWS ECS & CloudFormation, you should try ECS Compose-X which will take care of creating all your CFN templates for you from the docker compose definition, allowing you to add other things such as the LoadBalancer, the VPC (or use the existing one) etc. You could also see about ECS CLI v2

But here, the error about missing [TargetGroup, Listener] means that these two things are neither a Parameter nor a resource in the template and are "missing".

profile picture
답변함 9달 전
profile picture
전문가
검토됨 11일 전
profile pictureAWS
전문가
검토됨 9달 전
  • Thank you for your answer. I have created the cloudformation template and added load balancer. It's showing 0 healthy and 0 unhealthy. The DNS Name url is not accessible showing 503 Service Temporarily Unavailable.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠