我有一些网络负载均衡器的CloudFormation。
PrivateNetworkLoadBalancerSG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Access to the internal network load balancer
VpcId: !Ref 'VPC'
PrivateNetworkLoadBalancerIngressFromECS:
Type: AWS::EC2::SecurityGroupIngress
Properties:
Description: Only accept traffic from a container in the container host security group
GroupId: !Ref 'PrivateNetworkLoadBalancerSG'
IpProtocol: -1
SourceSecurityGroupId: !Ref 'EcsHostSecurityGroup'
PrivateNetworkLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Type: network
Scheme: internal
Subnets:
- !Ref PrivateSubnetOne
- !Ref PrivateSubnetTwo
DummyTargetGroupPrivateNetwork:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name: !Join ['-', [!Ref 'AWS::StackName', 'drop-3']]
Port: 6379
Protocol: TCP
# UnhealthyThresholdCount: 2
VpcId: !Ref 'VPC'还有一些用于在ECS中设置Redis码头容器。
RedisService:
Type: AWS::ECS::Service
Properties:
Cluster: !ImportValue "privatevpc:ClusterName"
DesiredCount: 1
TaskDefinition: !Ref RedisTaskDefinition
RedisTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: redis
ContainerDefinitions:
- Name: redis
Essential: true
Image: "redis:latest"
Memory: 512
PortMappings:
- ContainerPort: 6379
HostPort: 6379
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref CloudWatchLogsGroup
awslogs-region: !Ref AWS::Region
RedisTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
VpcId: !ImportValue "privatevpc:VPCId"
Port: 6379
Protocol: TCP
HealthCheckProtocol: TCP
RedisLoadBalancerListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref RedisTargetGroup
LoadBalancerArn: !ImportValue "privatevpc:PrivateNetworkLoadBalancer"
Port: 6379
Protocol: TCP但是,我必须手动添加EC2实例,RedisService通过AWS控制台作为RedisTargetGroup的目标进行部署。知道我怎么能让CloudFormation帮我这么做吗?
发布于 2019-03-07 02:02:12
我认为您需要将LoadBalancers属性添加到RedisService中。ECS应该自动向指定的目标组添加正确的EC2实例。
例如:
RedisService:
Type: AWS::ECS::Service
Properties:
Cluster: !ImportValue "privatevpc:ClusterName"
DesiredCount: 1
TaskDefinition: !Ref RedisTaskDefinition
LoadBalancers:
- ContainerName: redis
ContainerPort: 6379
TargetGroupArn: !Ref RedisTargetGrouphttps://stackoverflow.com/questions/55030635
复制相似问题