VPC – Nat Gateway – awscli


Amazon VPC

Amazon Virtual Private Cloud (VPC) A Amazon Virtual Private Cloud (Amazon VPC) permite provisionar uma seção da nuvem da Amazon Web Services (AWS) isolada logicamente, onde é possível executar recursos da AWS em uma rede virtual que você mesmo define.

AWS CLI

A AWS Command Line Interface (CLI, interface da linha de comandos) é uma ferramenta unificada para o gerenciamento de seus serviços da AWS. Com apenas uma ferramenta para fazer o download e configurar, você poderá controlar vários serviços da AWS pela linha de comandos e automatizá-los usando scripts.

Link para instalação do AWS CLI

https://docs.aws.amazon.com/pt_br/cli/latest/userguide/installing.html

Go!

Step 1 – Create VPC cidr 10.0.0.0/22

aws ec2 create-vpc --cidr-block 10.0.0.0/22
{
"Vpc": {
"VpcId": "vpc-a4f76ec2", 
"InstanceTenancy": "default", 
"Tags": [], 
"State": "pending", 
"DhcpOptionsId": "dopt-d600c5b3", 
"CidrBlock": "10.0.0.0/22", 
"IsDefault": false
}
}

Step 2 – Create Subnet Cidr 10.0.0.0/24 in zone us-east-1a

aws ec2 create-subnet --vpc-id vpc-a4f76ec2 --cidr-block 10.0.0.0/24 --availability-zone us-east-1a
{
"Subnet": {
"VpcId": "vpc-a4f76ec2", 
"CidrBlock": "10.0.0.0/24", 
"State": "pending", 
"AvailabilityZone": "us-east-1a", 
"SubnetId": "subnet-bda4e7e6", 
"AvailableIpAddressCount": 251
}
}

Step 3 – Create Subnet Cidr 10.0.1.0/24 in zone us-east-1c

aws ec2 create-subnet --vpc-id vpc-a4f76ec2 --cidr-block 10.0.1.0/24 --availability-zone us-east-1c
{
"Subnet": {
"VpcId": "vpc-a4f76ec2", 
"CidrBlock": "10.0.1.0/24", 
"State": "pending", 
"AvailabilityZone": "us-east-1c", 
"SubnetId": "subnet-ae085c83", 
"AvailableIpAddressCount": 251
}
}

Step 4 – Create Subnet Cidr 10.0.2.0/24 in zone us-east-1d

aws ec2 create-subnet --vpc-id vpc-a4f76ec2 --cidr-block 10.0.2.0/24 --availability-zone us-east-1d
{
"Subnet": {
"VpcId": "vpc-a4f76ec2", 
"CidrBlock": "10.0.2.0/24", 
"State": "pending", 
"AvailabilityZone": "us-east-1d", 
"SubnetId": "subnet-2264616b", 
"AvailableIpAddressCount": 251
}
}

Step 5 – Create Subnet Cidr 10.0.3.0/24 in zone us-east-1e

aws ec2 create-subnet --vpc-id vpc-a4f76ec2 --cidr-block 10.0.3.0/24 --availability-zone us-east-1e
{
"Subnet": {
"VpcId": "vpc-a4f76ec2", 
"CidrBlock": "10.0.3.0/24", 
"State": "pending", 
"AvailabilityZone": "us-east-1e", 
"SubnetId": "subnet-ce7cf5f2", 
"AvailableIpAddressCount": 251
}
}

Step 5 – Create Internet Gateway

aws ec2 create-internet-gateway
{
"InternetGateway": {
"Tags": [], 
"InternetGatewayId": "igw-6b633c0c", 
"Attachments": []
}
}

Step 6 – Attaching Internet Gateway in VPC 10.0.0.0/22

aws ec2 attach-internet-gateway --internet-gateway-id "igw-6b633c0c" --vpc-id "vpc-a4f76ec2"

Step 7 – Collecting router information

aws ec2 describe-route-tables --filters "Name=vpc-id,Values=vpc-a4f76ec2"
{
"RouteTables": [
{
"Associations": [
{
"RouteTableAssociationId": "rtbassoc-223cb55a", 
"Main": true, 
"RouteTableId": "rtb-92578ceb"
}
], 
"RouteTableId": "rtb-92578ceb", 
"VpcId": "vpc-a4f76ec2", 
"PropagatingVgws": [], 
"Tags": [], 
"Routes": [
{
"GatewayId": "local", 
"DestinationCidrBlock": "10.0.0.0/22", 
"State": "active", 
"Origin": "CreateRouteTable"
}
]
}
]
}

Step 8 – Creating default router for cidr 0.0.0.0/0

aws ec2 create-route --route-table-id "rtb-92578ceb" --destination-cidr-block "0.0.0.0/0" --gateway-id="igw-6b633c0c"
{
"Return": true
}

Step 9 – Allocating elastic ip

aws ec2 allocate-address --domain vpc
{
"PublicIp": "34.198.100.13", 
"Domain": "vpc", 
"AllocationId": "eipalloc-42dbce7c"
}

Step 10 – Create Nat Gateway and allocating elastic ip

 aws ec2 create-nat-gateway --subnet-id subnet-bda4e7e6 --allocation-id eipalloc-42dbce7c
{
"NatGateway": {
"NatGatewayAddresses": [
{
"AllocationId": "eipalloc-42dbce7c"
}
], 
"VpcId": "vpc-a4f76ec2", 
"State": "pending", 
"NatGatewayId": "nat-0065b009af4399d5b", 
"SubnetId": "subnet-bda4e7e6", 
"CreateTime": "2017-02-04T17:45:57.342Z"
}
}

Step 11 – Create router for VPC cidr 10.0.0.0/22

aws ec2 create-route-table --vpc-id vpc-a4f76ec2
{
"RouteTable": {
"Associations": [], 
"RouteTableId": "rtb-0d4d9674", 
"VpcId": "vpc-a4f76ec2", 
"PropagatingVgws": [], 
"Tags": [], 
"Routes": [
{
"GatewayId": "local", 
"DestinationCidrBlock": "10.0.0.0/22", 
"State": "active", 
"Origin": "CreateRouteTable"
}
]
}
}

Step 12 – Listing information from the nat gateway

aws ec2 describe-nat-gateways
{
"NatGateways": [
{
"NatGatewayAddresses": [
{List
"PublicIp": "34.198.100.13", 
"NetworkInterfaceId": "eni-081221cd", 
"AllocationId": "eipalloc-42dbce7c", 
"PrivateIp": "10.0.0.185"
}
], 

Step 13 – Creating default router for cidr 0.0.0.0/0

aws ec2 create-route --route-table-id rtb-0d4d9674 --destination-cidr-block 0.0.0.0/0 --nat-gateway-id nat-0065b009af4399d5b
{
"Return": true
}

Step 14 – Associating the Nat Gateway in the subnet as default gateway – (subnet-ce7cf5f2 – 10.0.3.0/24)

aws ec2 associate-route-table --route-table-id rtb-0d4d9674 --subnet-id subnet-ce7cf5f2
{
"AssociationId": "rtbassoc-52cb432a"
}
VPC – Nat Gateway – awscli
Tagged on:

Deixe uma resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

%d blogueiros gostam disto: