How to create Private and Public subnets in GCP? - google-cloud-platform

How to create Private and Public subnets in GCP? It is not same as AWS.

In GCP tags decides whether a subnet is private or public.
For public network create routes in VPC section and select the next-hop to Default Internet gateway
For private network create routes in VPC section and select the next-hop to specify and instance and select the nat instance

When create VM , you can change external IP to none.
This will requir NAT / LB to expose services and something like bastion server to login.

Though it's been a while since this was posted but thought to post this anyway as I ran into the same issue. I was doing a GCP-based lab challenge with an instruction to make a VPC private but I couldn't figure it out until I found this statement from an AWS doc located here.
If your subnet is associated with a route table that has a route to an >internet gateway, it's known as a public subnet.
In GCP you will need to remove the default route for internet access to make the VPC private. To make machines in the VPC gain internet access to download updates for example, you will need to create a cloud NAT gateway with cloud router

Related

How to transfer the packets through NAT gateway instead of public IP?

Using AWS services - I have used VPC and divided it into two subnets(private and public), then created two route tables(private and public), created one Internet gateway and attached to the public route table and one NAT Gateway connected to the private route table also both the route tables are mapped to their respective subnets but the problem is I need to deploy some code in the ec2 instance whose IP should not go without touching NAT Gateway.
I had many articles and also followed youtube but still I am very much confused like how to achieve this and whatever I did is right or wrong.
Also NAT gateway should be attached in private or public?
Also NAT gateway should be attached in private or public?
NAT should be deployed in public subnet. Then for your private subnet, you setup a route to the NAT.
Once this is done, you place your EC2 instance in the private subnet. This way, any internet traffic from the instance will be routed through the NAT.

Outbound Traffic from Private Subnet in AWS

Can I download and install patches from Internet using Route53, without having NAT Gateway and IGW?
I think you might be a little confused regarding what Route53 is:
Amazon Route 53 is a highly available and scalable cloud Domain Name System (DNS) web service.
Source
So, it has nothing to do with downloading patches. You can use it to handle your domains, and it can work nicely with several AWS services.
Now, regarding your question. If you want an EC2 instance to access the Internet and download its security patches, you will need an Internet Gateway configured on the VPC of the instance. On the other hand, the NAT Gateway is only necessary if your instance is configured on a private subnet. A private subnet doesn't have direct access to the Internet Gateway, so you need to provide a NAT Gateway to allow your instances to reach it. EC2 instances in public subnets can be assigned public IPs. An instance with a Public IP can access the Internet directly through the Internet Gateway without needing a NAT Gateway.
Another resource you are going to have to configure is Route Tables. Each subnet is assigned to a single Route Table. Once attached, it will use the routes define on the Route Table to handle their instances traffic. A Route Table that handles private subnets will have a default route pointing to a NAT Gateway. And a public Route Table will have a default route pointing directly to the Internet Gateway. Bear in mind that the NAT Gateway should always be instantiated on public subnets.
Take a look at the following documentation site for more information:
VPC Internet Gateway
VPC Subnet
VPC Route Tables
Route53 is a DNS service and its function is DNS resolution. You need NAT Gateway for outbound internet access from private subnet

AWS, Static IP on Lambda

I have a Lambda function (NodeJS) which consume an API that need to be accesed from certains IP, so team under the API ask me "please, provide us your IP to add it to the white list", but I'm not sure where or how to configure that static IP on AWS, where should I look?
Since #maurice show you the way, I will try to add some insight though I had to build a similar infrastructure like yours:
Third party provider requests us a static IP to connect to their API and our code was in a Lambda function (NodeJS).
In this case we did not want the lambdas to be reachable from outside, so we built two Subnets, one private and another one public. Lambdas go inside the private, which route Table 0.0.0.0/0 uses a NAT attached to the public subnet to manage the traffic that needs to connect to the Internet. Let me show you a few screenshots:
The Lambda must be in a VPC subnet with a NAT-Gateway.
The private subnet route table, which shows a NAT attachment:
The NAT belongs to the public subnet, and has an elastic IP attached (this is the key):
The public subnet has the following route table (everything is managed by the IGW):
This is something that is currently running in production environment and works flawless
You can't provide a static IP in a Lambda function directly.
You could deploy the Lambda function in a private subnet of a VPC that uses a NAT-Gateway for internet connectivity.
This NAT-Gateway will have an Elastic-IP, which you can tell your provider
(For high-availability you should have one NAT gateway per region).

Modify subnets to a VPC endpoint

I recently turned my two AWS public subnets into private subnets and added a public subnet that's got a NAT gateway. The private subnet routing table routs traffic to the NAT gateway and the public one routs it to the Internet Gateway. However, it isn't working and I don't get response to my API calls.
I think this is due to the fact that my VPC endpoint has the two private subnets associated with it instead of the public subnet. I tried to change the associated private subnets to the public one but got the AWS error:
Error modifying subnets
Can't change subnets of a requester-managed endpoint for the service ...
What would be the way to get around this error and add my public subnet to the VPC endpoint?
Additional info: Each private subnet has an EC2 auto-scaling group instance and a serverless aurora DB instance in it.
Cheers, Kris
I also had this annoying problem. The error messages are not really helpful here. They do not reveal which service exactly created those interfaces. So I went to Cloudtrail, listed all events, and searched for the VPC Endpoint name (vpce-1234567890xxx) that refused to be deleted to find out who created it. In my case, it turned out to be the RDS proxy service. So I went to RDS and deleted the proxy.
Since it is requester-managed VPC endpoint:
You cannot modify or detach a requester-managed network interface.
This means that you have to delete the resource that created the endpoint in the first place:
If you delete the resource that the network interface represents, the AWS service detaches and deletes the network interface for you.

Do I need NAT gateway and route table in a VPC if I don't want internet access?

I am going to build a Lambda and a RDS aurora for my application. The RDS aurora needs to be inside a VPC and it doesn't need internet access. I have read a lot articles about VPC setup for database and all of them mentioned that need to create VPC, public/private subnets, route table, NAT gateway and internet gateway.
However, in my case, I don't need internet access in the database VPC. So my question is do I need NAT gateway and route table at all? I know each VPC has a default route table, is the default route table good enough? If I just create a VPC with 3 private subnets and attach the VPC to my lambda. Does it work?
Your understanding is correct and you don't need any NAT.
NAT is specifically used for accessing public internet from private subnet, but it doesn't seem to be required here.
Just make sure your Lambda doesn't need to access any external entity or AWS Service as well (Like S3). If you are required to access an AWS Service, you may create a VPC Endpoint for it. (Linked example is for S3)