AWS Application in Private EC2 and HTTP traffic

一个人想着一个人 提交于 2019-12-03 08:37:24

So, it turns out there is an strange behaviour (bug?) in NLB that requires a default route to something for return traffic to work.

Scenario:

  • NLB in Public Subnet
  • NLB Target Group pointing to an instance in a Private Subnet

Sending traffic to the NLB will not give a response.

Add:

  • NAT Gateway
  • Add a route in the Private Route Table to point to the NAT Gateway

This works.

However, it doesn't actually use the NAT Gateway!

Instead of adding a NAT Gateway, you can instead create a default route to another instance, for example:

0.0.0.0/0 -> another instance

Then, connecting to the NLB works!

Behind the scenes, the VPC network detects that traffic coming out of the instance is in response to a request that came via the NLB, and traffic will be routed out the NLB.

HOWEVER, it only works if there is a valid default route in the route table. The route isn't used -- the network overrides it, so it doesn't matter what it points to. However, it must point to a valid resource. It doesn't work if it points to an ENI that isn't attached to anything. In my tests, it also doesn't seem to work if you point it back to the same instance. But, I pointed it to another instance and it worked just fine.

AWS Support agrees that this is not the best behaviour, but it's how things have to be configured for the moment.

Bottom line: It does not require a NAT Gateway. It just needs a valid default route that will be ignored when routing return traffic.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!