Keep bragging

Notes on technologies, coding, and algorithms

AWS infrastructure

VPC

Amazon Virtual Private Cloud (Amazon VPC) is the network layer for EC2, which enables users to launch AWS resources into a virtual network that they define. This virtual network closely resembles a traditional network that users’d operate in their own data center, with the benefits of using the scalable infrastructure of AWS

Core concepts are:

VPC and commands

CIDR

Private IP range conforms to RFC 1918:

Secondary CIDR can’t overlap with primary CIDR. You can’t specify IPv6 CIDR, which is assigned by AWS at your request. All IPv6 addresses are public, reachable from internet.

VPC

aws ec2 create-vpc --cidr-block 192.168.0.0/28 --profile fargate
aws ec2 describe-vpcs --vpc-id vpc-0ca77f7a1eaa670da --profile fargate
aws ec2 delete-vpc --vpc-id vpc-0ca77f7a1eaa670da --profile fargate

aws ec2 create-vpc --cidr-block 192.168.0.0/16 --profile fargate
aws ec2 describe-vpcs --vpc-id vpc-0b39341d010ee6478 --profile fargate

Subnet

AWS reserves first 4 IP and last IP in the subnet, which can’t be assigned to any instance

aws ec2 create-subnet --vpc-id vpc-0b39341d010ee6478 --cidr-block 192.168.0.0/24 --availability-zone us-west-2a  --profile fargate
aws ec2 describe-subnets --subnet-ids subnet-02a787cb22db69c9f --profile fargate

ENI (elastic network interface)

aws ec2 create-network-interface --private-ip-address 192.168.0.99 --subnet-id subnet-02a787cb22db69c9f --profile fargate
aws ec2 describe-network-interfaces --network-interface-ids eni-00cc465d706a3e19f --profile fargate

Internet gateway

aws ec2 create-internet-gateway --profile fargate
aws ec2 attach-internet-gateway --internet-gateway-id igw-093bbac28c9ea0d9e --vpc-id vpc-0b39341d010ee6478 --profile fargate
aws ec2 describe-route-tables --filters Name=vpc-id,Values=vpc-0b39341d010ee6478 --profile fargate
aws ec2 create-route --route-table-id rtb-0a9cbff5674cf1bfd --destination-cidr-block "0.0.0.0/0"  --gateway-id igw-093bbac28c9ea0d9e  --profile fargate

NAT

NAT gateway/devices translates private IP to public IP or vice versa so the private subnet instances can access internet for software upgrade etc.

NAT devices must reside in different subnet than private subnet instances. Each subnet has its own route table. For private subnet, it has its default route to NAT device/gateway, while NAT device/gateway, it resides in public subnet which has default route to internet gateway.

security group

aws ec2 create-security-group --group-name "web-ssh" --description  "web and ssh traffic" --vpc-id vpc-0b39341d010ee6478 --profile fargate
aws ec2 authorize-security-group-ingress  --group-id sg-09bda85178ea66b93 --protocol tcp --cidr 0.0.0.0/0 --port 22  --profile fargate
aws ec2 authorize-security-group-ingress  --group-id sg-09bda85178ea66b93 --protocol tcp --cidr 0.0.0.0/0 --port 80  --profile fargate
aws ec2 authorize-security-group-ingress  --group-id sg-09bda85178ea66b93 --protocol tcp --cidr 0.0.0.0/0 --port 443  --profile fargate
aws ec2 describe-security-groups --group-id sg-09bda85178ea66b93 --profile fargate

NACL

aws ec2 create-network-acl  --vpc-id vpc-0b39341d010ee6478 --profile fargate

Inbound rule

aws ec2 create-network-acl-entry --ingress --cidr-block "0.0.0.0/0" --protocol tcp --port-range "From=22,To=22" --rule-action allow --network-acl-id acl-0da6f3db6189257ca --rule-number 70  --profile fargate
aws ec2 create-network-acl-entry --ingress --cidr-block "54.240.196.172/32" --protocol tcp --port-range "From=3389,To=3389" --rule-action allow --network-acl-id acl-0da6f3db6189257ca --rule-number 80  --profile fargate
aws ec2 describe-network-acls --network-acl-id acl-0da6f3db6189257ca --profile fargate

Outbound rule

Public IP Address

Elastic IP address (EIP)

aws ec2 allocate-address --profile fargate
aws ec2 associate-address --allocation-id eipalloc-08837e12a89b6b3b8 --network-interface-id  eni-00cc465d706a3e19f --profile fargate

3 ways to connnect on-premise network with VPCs

Transit gateay

Create a new VPC and subnet
aws ec2 create-vpc --cidr-block 172.17.0.0/16 --profile fargate
aws ec2 create-subnet --vpc-id vpc-066860d387cd31fc4 --cidr-block 172.17.0.0/24 --availability-zone us-west-2b  --profile fargate
aws ec2 describe-route-tables --filters Name=vpc-id,Values=vpc-066860d387cd31fc4 --profile fargate

Create transit gateway

aws ec2 create-transit-gateway --profile fargate
aws ec2 describe-transit-gateways --transit-gateway-id tgw-0dd6d9997e516c4a8 --profile fargate
aws ec2 create-transit-gateway-vpc-attachment --transit-gateway-id  tgw-0dd6d9997e516c4a8 --vpc-id vpc-066860d387cd31fc4 --subnet-ids subnet-051aa1d68a65c2add  --profile fargate
aws ec2 create-transit-gateway-vpc-attachment --transit-gateway-id  tgw-0dd6d9997e516c4a8 --vpc-id vpc-0b39341d010ee6478 --subnet-ids subnet-02a787cb22db69c9f  --profile fargate

aws ec2 search-transit-gateway-routes --transit-gateway-route-table-id tgw-rtb-0c3c917e07c11cddc --filters "Name=type,Values=static,propagated" --profile fargate

aws ec2 create-route --route-table-id rtb-0a9cbff5674cf1bfd --destination-cidr-block "172.17.0.0/16" --transit-gateway-id tgw-0dd6d9997e516c4a8  --profile fargate
aws ec2 create-route --route-table-id rtb-0f402bcb6a0812351 --destination-cidr-block "192.168.0.0/16" --transit-gateway-id tgw-0dd6d9997e516c4a8  --profile fargate

aws ec2 create-transit-gateway-route --destination-cidr-block "192.168.100.64/29" --transit-gateway-route-table-id tgw-rtb-0c3c917e07c11cddc --blackhole --profile fargate
aws ec2 search-transit-gateway-routes --transit-gateway-route-table-id tgw-rtb-0c3c917e07c11cddc --filters "Name=type,Values=static,propagated" --profile fargate

aws ec2 delete-transit-gateway-vpc-attachment --transit-gateway-attachment-id tgw-attach-0562f8bbbbccb777c --profile fargate
aws ec2 delete-transit-gateway-vpc-attachment --transit-gateway-attachment-id tgw-attach-092995ddfe103333e --profile fargate
aws ec2 search-transit-gateway-routes --transit-gateway-route-table-id tgw-rtb-0c3c917e07c11cddc --filters "Name=type,Values=static,propagated" --profile fargate
aws ec2 describe-transit-gateways --transit-gateway-id tgw-0dd6d9997e516c4a8 --profile fargate
aws ec2 delete-transit-gateway --transit-gateway-id tgw-0dd6d9997e516c4a8 --profile fargate