【发布时间】:2022-02-04 03:44:20
【问题描述】:
我们正在使用 CloudFormation 创建一个网络负载均衡器。目标类型为IP,需要指向一个VPC端点的IP地址。
所以我们需要创建一个“ip”类型的目标组,并指定一个目标列表:
NetworkLoadBalancerTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name: !Sub '${AWS::StackName}-NLT'
Port: 443
Protocol: TLS
VpcId: !Ref 'VPC'
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: 300
TargetType: ip
Targets: # list of the primary IP addresses of the Network interface(s) associated with the VPC endpoint
- ?????
目标必须是 VPC 终端节点的 IP 地址。如何引用这些?
VPC 端点是这样创建的:
VpcEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcEndpointType: Interface
SubnetIds:
- !Ref ProtectedSubnetA
- !If [IsProd, !Ref ProtectedSubnetB, !Ref 'AWS::NoValue']
- !If [IsProd, !Ref ProtectedSubnetC, !Ref 'AWS::NoValue']
SecurityGroupIds:
- !Ref SecurityGroupHttpsInInternal
- !Ref SecurityGroupHttpsOutInternal
PrivateDnsEnabled: true
ServiceName: !Sub com.amazonaws.${AWS::Region}.execute-api
VpcId: !Ref VPC
PolicyDocument: '{
"Statement": [
{
"Action": "*",
"Effect": "Allow",
"Resource": "*",
"Principal": "*"
}
]
}'
我可以获得这样的网络接口 ID 列表:
!GetAtt VpcEndpoint.NetworkInterfaceIds
但是,这是一个字符串列表。如何获取 id 列表中每个网络接口的 PrimaryPrivateIpAddress 属性?
为了完整起见,这里是网络负载均衡器和相关监听器的定义:
NetworkLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
LoadBalancerAttributes:
- Key: load_balancing.cross_zone.enabled
Value: true
Name: !Sub '${AWS::StackName}-NLB-Protected'
Scheme: internal
Subnets:
- !Ref ProtectedSubnetA
- !If [IsProd, !Ref ProtectedSubnetB, !Ref 'AWS::NoValue']
- !If [IsProd, !Ref ProtectedSubnetC, !Ref 'AWS::NoValue']
Type: network
NetworkLoadBalancerListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref NetworkLoadBalancerTargetGroup
LoadBalancerArn: !Ref NetworkLoadBalancer
Port: '443'
Protocol: TLS
SslPolicy: ELBSecurityPolicy-TLS-1-2-Ext-2018-06
Certificates:
- CertificateArn: !Ref ACMCertificate
【问题讨论】:
标签: amazon-web-services amazon-cloudformation amazon-elb