问题
i have two instances in two different availability-zones which need to communicate with each other. they are inside vpc private subnets-
a) Will the traffic go through NAT when they talk to each other ?
b) And what will happen if they are in public subnet and have elastic ip attached ?
c) What if they are in ec2 classic in two different az ?
回答1:
All of these scenarios can go either way, depending on how the instances address each other.
All VPC instances have a private IP address, even if they also have an Elastic (public) IP or a dynamic public IP from the pool.
As long as A connects to B using B's private IP address as the destination, the traffic will not use B's public IP, and will not traverse the NAT (when A doesn't have a public IP) and will not use A's public or elastic IP (if it has one).
If A connects to B using B's public address as the destination (if B has one) then none of the statements in the previous paragraph will hold true... So, you almost always want to use the private IP of an instance when connecting to another instance.
That also holds true in EC-Classic.
You will also pay for data transfer between instances in different availability zones, and in the same AZ if the instances are in two different VPCs (using VPC peering). As of this writing, the charge is $0.02/GB. In most cases, to be precise, one instance is charged $0.01 to send the data, and the other is charged $0.01 to receive it, but that's a net of $0.02. Conversely, when instances communicate with each other across two different regions, the sending instance pays $0.02 and the receiving instance pays $0.00... and, of course, public IPs are always involved at some layer of a multi-region setup.
You don't pay for data transfer between instances in the same AZ (and VPC, if VPC) unless you use NAT or elastic/public IP addresses, which -- aside from potential and unnecessary loss of performance -- is another reason not to do that... which, again, should only happen if one instance does not connect to the the other using private IP addresses as the destination address.
来源:https://stackoverflow.com/questions/29833523/aws-cross-az-traffic