- 新しい順
- 投票が多い順
- コメントが多い順
I would try a DependsOn in the Service resource waiting on the Listener to be created.
Service:
Type: AWS::ECS::Service
DependsOn: PublicLoadBalancerListener
Properties:
ServiceName: !Ref 'ServiceName'
...
The error message indicates that the target group associated with the service does not have an associated load balancer. Based on the code you provided, it seems like the service is attempting to create a new load balancer and associate it with the target group. However, it's possible that the load balancer was previously created and is no longer associated with the target group.
To fix the issue, you can try the following:
Check if a load balancer exists: You can check in the AWS Management Console to see if there is an existing load balancer. If there is, you can try to associate the load balancer with the target group.
Update the service to use an existing load balancer: If a load balancer already exists, you can modify the service YAML to use the existing load balancer instead of creating a new one. You can use the "LoadBalancerArn" property to specify the ARN of the existing load balancer.
Here is an example of how you can modify the YAML to use an existing load balancer:
Service: Type: AWS::ECS::Service Properties: ServiceName: !Ref 'ServiceName' Cluster: Fn::ImportValue: !Join [':', [!Ref 'StackName', 'ClusterName']] DeploymentConfiguration: MaximumPercent: 100 MinimumHealthyPercent: 0 DesiredCount: !Ref 'DesiredCount' TaskDefinition: !Ref 'TaskDefinition' NetworkConfiguration: AwsvpcConfiguration: Subnets: - Fn::ImportValue: !Join [':', [!Ref 'StackName', 'PrivateSubnetOne']] - Fn::ImportValue: !Join [':', [!Ref 'StackName', 'PrivateSubnetTwo']] SecurityGroups: [!Ref 'PublicLoadBalancerSG'] AssignPublicIp: 'DISABLED' LoadBalancers: - ContainerName: !Ref 'ServiceName' ContainerPort: !Ref 'ContainerPort' TargetGroupArn: !Ref 'TargetGroup' TargetGroup: Type: AWS::ElasticLoadBalancingV2::TargetGroup Properties: HealthCheckProtocol: TCP HealthCheckIntervalSeconds: 10 HealthyThresholdCount: 2 UnhealthyThresholdCount: 2 Name: !Ref 'ServiceName' Port: !Ref 'ContainerPort' Protocol: TCP TargetType: ip VpcId: Fn::ImportValue: !Join [':', [!Ref 'StackName', 'VPCId']] PublicLoadBalancerListener: Type: AWS::ElasticLoadBalancingV2::Listener Properties: DefaultActions: - TargetGroupArn: !Ref 'TargetGroup' Type: 'forward' LoadBalancerArn: <existing load balancer ARN> Port: !Ref ContainerPort Protocol: TCP
Make sure to replace <existing load balancer ARN> with the ARN of the existing load balancer.
Thank you very much for your reply. I will try this, the only issue is that my script was working before and the aws specialist who once helped me get it working made one script that creates the cluster, then references the created items (such as the loadbalancer that was created right before the service attempted to get created. What is going wrong? Is it possible to reference the loadbalancer dynamically?
Mary
Can you show me how to write it in my yaml snippet?