0

I am able to create a subnet in my vpc. But, its a public subnet. However I would like to create a private subnet associated to my VPC. How could I acheive that. Thanks.

private static Subnet createSubnet(AmazonEC2 ec2, String vpcId, String az, String subnetACidrBlock)

 CreateSubnetRequest csr = new CreateSubnetRequest();
    csr.withAvailabilityZone(az)
        .withCidrBlock(subnetACidrBlock)
        .withVpcId(vpcId);
    Subnet subnet = ec2.createSubnet(csr).getSubnet();
    System.out.println("Subnet " + subnet.getSubnetId());
    return subnet;

}

1 Answers1

0

You can set the private route table to the created subnet using ec2.associateRouteTable()

The difference between a "public" and a "private" subnet is in the route table. The subnet with a route table that does not route through an Internet Gateway or Virtual Gateway is private.

Julio Faerman
  • 13,228
  • 9
  • 57
  • 75
  • 1
    I tried using the route table with no Internet Gateway attached. If that is the case, my EMR cluster which is running in my VPC private subnet is not communicating to outside world i.e., my S3. @Julio Faerman –  Sep 22 '14 at 21:55
  • That is right, currently you need a internet gateway for EMR – Julio Faerman Sep 23 '14 at 12:15