Is a NAT instance required in every vpc? - amazon-web-services

I have a hub and spoke model for infrastructure with a management vpc and 4-5 different environment vpc, peered to the management vpc.
I already have it set up but currently I only have 1 nat instance and 1 bastion host. Both of which are in the management vpc public subnet.
I wish to connect an instance in an environment vpc in a private subnet to this NAT instance to be able to reach the internet. Is that possible?
Note: I have the NAT/Bastion working correctly in the management vpc. I can reach all servers in both vpc with the Bastion host. I just can't get the above working.
My question is... is it possible? or do I need to set up an NAT in every vpc?

Edge to edge routing through a gateway (including the VPC Internet Gateway or IGW) is an unsupported VPC configuration with VPC peering.
Example: Edge to Edge Routing Through an Internet Gateway
Let's say you have a VPC peering connection between VPC A and VPC B (pcx-abababab). VPC A has an internet gateway; VPC B does not. Edge to edge routing is not supported; you cannot use VPC A to extend the peering relationship to exist between VPC B and the internet. For example, traffic from the internet can’t directly access VPC B by using the internet gateway connection to VPC A.
Similarly, if VPC A has a NAT device that provides internet access to instances in private subnets in VPC A, instances in VPC B cannot use the NAT device to access the internet.

Transit Gateway seems to fit for the case.
Transit Gateway Example: Centralized Router
The following diagram shows the key components of the configuration for this scenario. In this scenario, there are three VPC attachments and one Site-to-Site VPN attachment to the transit gateway. Packets from the subnets in VPC, A, VPC B, and VPC C that have the internet as a destination, route first through the transit gateway and then route to the VPN.

Related

Routing to a NAT instance across VPCs through a Transit Gateway

I have an instance in a private subnet in VPC B. I want to direct all of its outbound traffic through a NAT instance that is in VPC A.
VPC A and B are associated with a Transit Gateway and the instances from each VPC can ping each other. The NAT instance is obviously in a public subnet, and I confirmed it works by routing an instance in a private subnet in the same VPC to the NAT Instance's ENI.
I tried adding the respective routes and its not working, the instance in private subnet in VPC B cannot reach internet. There is definitely some fundamental step I am missing, either in the routing or simply the whole concept.
Would really appreciate the assistance or general direction I should check.
High level diagram of env
I sorted it out, it wasn't an issue with routing. I simply didn't set up my NAT instance properly. Once I fixed that it worked (Made sure I had proper NAT rules).
I actually went with a more complex method and created a Customer Gateway and Site-to-Site VPN connection with the NAT Instance and attached that to my TGW.

How to access the internet via other VPC NAT?

Background
I have two Google Cloud VPC networks. VPC A and B. B network was peered into A network.
The VPC A has a NAT gateway with connectivity to the internet.
Instances running in VPC B has no internet connectivity.
Question
I want to connect VPC B to use A NAT in order to get internet connectivity.
How to do it?
As per VPC Network Peering interaction this isn't possible:
Cloud NAT gateways are associated with subnet IP address ranges in a single region and a single VPC network. A Cloud NAT gateway created in one VPC network cannot provide NAT to VMs in other VPC networks connected by using VPC Network Peering, even if the VMs in peered networks are in the same region as the gateway.
It is possible to achieve the result you are looking for by using a Shared VPC instead of VPC Network Peering, this would allow an organization to connect resources from multiple projects to a common VPC network.
Here you have be the steps you need to follow to create a Shared VPC.

AWS VPC with internet access sometimes timeouts with outside requests

I've created a VPC (due to the RDS connectivity needs inside the lambdas) in AWS which has internet access most of the time, but some times my outside requests timeout (mostly these happen with SES as they're the majority of outside requests). I've configured my VPC the following way (sorry, not in the created order, just reading them off AWS):
VPC with 172.30.0.0/16 CIDR
3 private subnets with 172.30.0.0/24, 172.30.1.0/24, 172.30.2.0/24 and a different availability zone for each (1a, 1b, 1c) with 0.0.0.0/0 route targeting my NAT
1 public subnet with 172.30.3.0/24 to 1a availability zone with a 0.0.0.0/0 route targeting my IGW
2 route tables (private and public) with the 3 private subnets in the private route table and the public one in it's own
Security groups for lambdas directing all outbound traffic to 0.0.0.0/0
Lambdas are configured to use these subnets and the given security group.
I'm not understanding why my internet requests some times fail from inside the VPC, it's almost as if the lambda gets started at some availability zone and that specific one does not have access to the internet inside the vpc.
EDIT: Resolved! I had the public subnet listed in my lambda function which caused the timeouts
AWS Lambda functions that are connected to a VPC should always be configured to use private subnets.
If those Lambda functions also require Internet access, they can use a NAT Gateway or NAT Instance to reach the Internet. These NAT services should be configured to use the public subnet(s).
When the Lambda function is connected to a private subnet, then traffic destined for the Internet will be routed from the private subnet, through the NAT Gateway/NAT Instance, and out to the Internet. This will not work if the Lambda function is connected to a public subnet. (And a Lambda function cannot connect directly from a VPC to the Internet.)

NAT Gateway with Internet Gateway and lambda

We use elastic beanstalk to run our main application out of EC2, we also have an RDS instance in that VPC. Those instances have public IPs so it can use a standard internet gateway to access the internet. No problems there.
Now I have created a lambda function, associated it with the 3 subnets corresponding to the 3 AZs the EC2 instances live in. Everything is still good. My lambda can connect to those resources just fine.
My problem is I need my lambda to reach the internet. Normally I'd route the subnets it's in to 0.0.0.0/0 and route it out through a NAT gateway. However, because the EC2 and RDS instances in the subnets of the VPC my lambda is associated with have public IPs putting a NAT gateway in breaks their internet connectivity. How should I go about giving my lambda internet access, without breaking the IGW for the other Ec2 instances?
I was thinking of maybe creating 3 new subnets within the 3 AZs, associating that with my lambda function, create a NAT gateway in each AZ subnet, make the corresponding routes for each subnet. If I did that would my lambda still be able to access the EC2\RDS instances within the other subnets? I have a lambda sg and an ec2 sg and the lambda sg is permitted access to the ec2 sg. Hopefully this makes sense!
As it is not possible to attach public IP addresses to Lambda functions, you have to launch them in private subnets and forward internet traffic to a NAT gateway/instance to let your functions access the Internet.
It looks like you have only created public subnets in your VPC. As you have already suggested, you need to create private subnets that hosts your lambda functions.
Create 1 public and 1 private subnet per AZ.
Launch NAT Gateways in public subnets.
Update the routing table of the private subnets and forward all internet traffic to the NAT GW.
Private subnet RT
0.0.0.0/0 --> NAT GW
Public subnet RT
0.0.0.0/0 --> IGW

Lambda function access rds instance (with Internet Gateway)

The link explains that need to use NAT Gateway for the public subnet to make it possible to access the internet and the lambda function access the RDS instance. First does it realy have to be NAT Gateway can't use instead a Internet Gateway for that purpose?
Second have two Route Tables one named PublicNetwork that haves two subnets and the route haves one Internet Gateway,
the second Route Table that haves only one subnet called PrivateNetwork.
when had only one Route Table with all 3 subnets could access the rds (db) instance with Microsoft SQL Server Management (security group with inbound rules of type MS SQL and Source my ip address) now with the changes can't access anymore.
My database in RDS haves in Subnet group my default-vpc that haves the 3 subnets is it needed to create another vpc and transfer the private subnet to it to be able to access my database again?
All subnets in a VPC can communicate with each other
An Internet Gateway connects the VPC to the Internet
Any subnet that has a Route Table pointing 0.0.0.0/0 to the Internet Gateway is called a Public Subnet (because it can directly communicate with the Internet)
Any subnet that does not have such a Route table entry is called a Private Subnet
If a resource in a private subnet needs to communicate with the Internet, it must send the network traffic via a NAT Gateway in the Public Subnet. The NAT Gateway will forward the traffic to the Internet, then return any response that is received.
If you are having difficulty connecting to resources within the same VPC, then the Security Group is the most likely cause of the problem.