Internet gateway

To access your VPC network, you need to have a gateway that accesses it from the internet. Internet Gateway (IGW) is the one that connects the internet to your VPC.

Then, in the subnets under VPC, you can set the default route to go to IGW or not. If it routes to IGW, the subnet is classified as the public subnet. Then, you can assign the global IP address on the public subnet.

Let's configure the first subnet (192.168.0.0/24) as the public subnet that routes to IGW using the following steps:

  1. Create IGW and capture InternetGatewayId:
$ aws ec2 create-internet-gateway
{
"InternetGateway": {
"Attachments": [],
"InternetGatewayId": "igw-e50b849d",
"Tags": []
}
}
  1. Attach IGW (igw-e50b849d) to your VPC (vpc-69cfbd12):
$ aws ec2 attach-internet-gateway --vpc-id vpc-69cfbd12 --internet-gateway-id igw-e50b849d
  1. Create a routing table on VPC (vpc-69cfbd12) and then capture RouteTableId:
$ aws ec2 create-route-table --vpc-id vpc-69cfbd12
{
"RouteTable": {
"Associations": [],
"PropagatingVgws": [],
"RouteTableId": "rtb-a9e791d5",
"Routes": [
{
"DestinationCidrBlock": "192.168.0.0/16",
"GatewayId": "local",
"Origin": "CreateRouteTable",
"State": "active"
}
],
"Tags": [],
"VpcId": "vpc-69cfbd12"
}
}
  1. Set the default route (0.0.0.0/0) for route table (rtb-a9e791d5) as IGW (igw-e50b849d):
$ aws ec2 create-route --route-table-id rtb-a9e791d5 --gateway-id igw-e50b849d --destination-cidr-block 0.0.0.0/0
  1. Associate route table (rtb-a9e791d5) to public subnet (subnet-6296863f):
$ aws ec2 associate-route-table --route-table-id rtb-a9e791d5 --subnet-id subnet-6296863f
  1. Enable autoassign public IP on the public subnet (subnet-6296863f):
$ aws ec2 modify-subnet-attribute --subnet-id subnet-6296863f --map-public-ip-on-launch
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.176.5