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
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.