Amazon VPC Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 167: Line 167:
     Type: [[Amazon_VPC_Concepts#Elastic_IP_Address|AWS::EC2::EIP]]
     Type: [[Amazon_VPC_Concepts#Elastic_IP_Address|AWS::EC2::EIP]]
     Properties:
     Properties:
      Domain: String
       InstanceId: String
       InstanceId: String
       PublicIpv4Pool: String
       PublicIpv4Pool: String
      Domain: String

Revision as of 04:20, 10 April 2019

Internal

Overview

VPC Operations

Create a VPC

Describe VPC

aws ec2 describe-vpcs --vpc-id <vpc-id>

Create a VPC with Amazon Console

VPC Console -> Your VPCs -> Create VPC:

Name tag: the name of the VPC

IPv4 CIDR block: 10.7.0.0/16

IPv6 CIDR block: No IPv6 CIDR Block

Tenancy: default

Create a VPC with CloudFormation

AWS::EC2::VPC
Resources:
  VPC:
    Type: AWS::EC2::VPC
    Properties: 
      CidrBlock: !Ref PrimaryIPAddressRange
      EnableDnsSupport: true
      EnableDnsHostnames: false
      InstanceTenancy: "default"
      Tags:
        - Key: "Name"
          Value: !Ref VPCName

Subnet Operations

AWS::EC2::Subnet

Create a Subnet

Create a Subnet with CloudFormation

Resources:
  Subnet1:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      CidrBlock: String
      AvailabilityZone: String
      AssignIpv6AddressOnCreation: Boolean
      Ipv6CidrBlock: String
      MapPublicIpOnLaunch: false
      Tags:
        - Key: Name
          Value: 'blue-subnet'

Route Table Operations

Create a Route Table

Create a Route Table with CloudFormation

AWS::EC2::RouteTable
[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet-route-table-assoc.html
Resources:

  RouteTable:
    Type: AWS::EC2::RouteTable
    Properties: 
        VpcId: !Ref VPC
        Tags:
          - Key: Name
            Value: "some-route-table"

  SubnetRouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties: 
      RouteTableId: !Ref RouteTable
      SubnetId: !Ref Subnet

Note that a route table is not associated with any subnet after creation, an AWS::EC2::SubnetRouteTableAssociation resource must be explicitly created to implement the association.

Create a Route

Create a Route with CloudFormation

AWS::EC2::Route
Resources:
  ARoute:
    Type: AWS::EC2::Route
    Properties: 
      RouteTableId: String
      DestinationCidrBlock: String
      DestinationIpv6CidrBlock: String
      GatewayId: String
      NatGatewayId: String
      NetworkInterfaceId: String
      InstanceId: String
      EgressOnlyInternetGatewayId: String
      VpcPeeringConnectionId: String

Internet Gateway Operations

Describe an Internet Gateway

aws ec2 describe-internet-gateways [--internet-gateway-ids igw-0f8b5a9295a707d16]

Create an Internet Gateway

AWS::EC2::InternetGateway
AWS::EC2::VPCGatewayAttachment
Resources:

  InternetGateway:
    Type: AWS::EC2::InternetGateway
    Properties: 
      Tags:
        - Key: Name
          Value: infinity-igw

  InternetGatewayVpcAttachment:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties: 
        InternetGatewayId: !Ref InternetGateway
        VpcId: !Ref VPC

Note that an internet gateway is not attached with an VPC after creation, an AWS::EC2::VPCGatewayAttachment resource must be created to attach the internet gateway to a VPC.

NAT Gateway Operations

Create a NAT Gateway

Create a NAT Gateway with Amazon Console

Create a NAT Gateway with Amazon Console

Create a NAT Gateway with CloudFormation

AWS::EC2::NatGateway
Resources:
  NATGateway:
    Type: AWS::EC2::NatGateway
    Properties: 
       SubnetId: !Ref PublicSubnet
       AllocationId: !Ref ElasticIP
       Tags: 
         - Key: Name
           Value: infinity-nat

Elastic IP Operations

Create an Elastic IP with CloudFormation

AWS::EC2::EIP
Resources:
  ElasticIPAddress:
    Type: AWS::EC2::EIP
    Properties:
      InstanceId: String
      PublicIpv4Pool: String
      Domain: String