Amazon web services 如何在CloudInformation中将目标添加到网络负载平衡器
我有一些关于网络负载均衡器的云信息Amazon web services 如何在CloudInformation中将目标添加到网络负载平衡器,amazon-web-services,amazon-cloudformation,aws-load-balancer,Amazon Web Services,Amazon Cloudformation,Aws Load Balancer,我有一些关于网络负载均衡器的云信息 PrivateNetworkLoadBalancerSG: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Access to the internal network load balancer VpcId: !Ref 'VPC' PrivateNetworkLoadBalancerIngressFromECS: Type: AWS
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 docker容器
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
但是我必须手动添加我的RedisService部署到的EC2实例,作为通过AWS web控制台的RedisTargetGroup的目标。你知道如何让CloudFormation为我做到这一点吗?我想你需要将
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 RedisTargetGroup
我认为可以通过一些示例来指导您,在这些示例中,他们创建了一些云信息资源,如您需要的资源:这就是我的起点。您需要添加自动缩放。你试过了吗?