我需要使用内部 NLB 与 VPC 内的其他资源进行通信。我能够在 VPC 内创建 NLB 和 AWS Lambda 函数,但由于某种原因,我来自 Lambda 的请求挂起并超时。我尝试过将 NLB 和 Lambda 函数放在不同的子网中、同一子网中、不同的 SG 中、同一 SG 中,但没有任何效果。我不确定您应该如何访问内部 NLB 来测试它们。以下是我使用 CloudFormation 所做的事情:
NLB: # The Network Load Balancer
Type: "AWS::ElasticLoadBalancingV2::LoadBalancer"
Properties:
Scheme: "internal"
Subnets: !Ref NlbSubnetIds # I'm providing 3 subnets out of the 6 available
Type: "network"
LoadBalancerAttributes:
- Key: access_logs.s3.enabled
Value: true
- Key: access_logs.s3.bucket
Value: !Ref AccessLogBucketNlb
- Key: load_balancing.cross_zone.enabled
Value: true
NlbTargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
HealthCheckIntervalSeconds: 30
HealthCheckProtocol: "TCP"
HealthyThresholdCount: 3
Matcher: !Ref "AWS::NoValue"
Port: 80
Protocol: "TCP"
TargetType: "ip"
UnhealthyThresholdCount: 3
VpcId: !Ref VpcId
NlbListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref NlbTargetGroup
LoadBalancerArn: !Ref NLB
Port: '80'
Protocol: TCP
来自同一 VPC 中我的 Lambda 函数:
import json
import urllib3
def lambda_handler(event, context):
http = urllib3.PoolManager()
r = http.request('GET', 'http://<NLB DNS Name>.elb.us-east-1.amazonaws.com',
headers={'Content-Type': 'application/json'})
print(r.read())
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
ACL 中的所有入站/出站规则都允许通信以及安全组,因此我确信事实并非如此。任何帮助将不胜感激。
您可以在同一 VPC 中创建一个 EC2 实例,并尝试使用该 EC2 实例访问 NLB。我们正在使用相同的方法来测试我们的端点