Search code examples
amazon-web-servicesaws-lambdaamazon-vpc

How to create a private subnet within my current VPC?


I have a VPC with 6 public subnet, I need to create a private one to deploy a lambda function that needs to connect to a DB, no need to have internet access.

The problem is that when I try to create a new one, it comes with an internet gateway attached to it.

How can I create a simple private subnet?


Solution

  • What makes a public subnet "public" is having a route table with a route to an internet gateway (IGW). Thus, any subnet which does not have such a route, is "private" by definition.

    In your case, probably your subnet is using a vpc's main route table, which has the route to IGW. In that case, create a new route table (by default it will not have a route to IGW) and associate it with the new subnet.

    This way your new subnet will use the new route table without IGW, and will be "private".