Wednesday, February 21, 2024
HomeSoftware EngineeringThe best way to create Public and Personal Subnets in CloudFormation

The best way to create Public and Personal Subnets in CloudFormation


To create private and non-private subnets in AWS CloudFormation, you should utilize the AWS CloudFormation Template Language (CFT) to outline your community configuration. Right here’s an instance CloudFormation template that demonstrates the right way to create private and non-private subnets inside a Digital Personal Cloud (VPC) in AWS:

Sources:
  MyVPC:
    Sort: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      Tags:
        - Key: Title
          Worth: my-vpc

  PublicSubnet:
    Sort: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref MyVPC
      CidrBlock: 10.0.0.0/24
      AvailabilityZone: us-west-2a
      Tags:
        - Key: Title
          Worth: public-subnet

  PrivateSubnet:
    Sort: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref MyVPC
      CidrBlock: 10.0.1.0/24
      AvailabilityZone: us-west-2b
      Tags:
        - Key: Title
          Worth: private-subnet

On this instance, the AWS::EC2::VPC useful resource creates a VPC with the desired CIDR block. The AWS::EC2::Subnet assets create the private and non-private subnets inside the VPC, utilizing completely different CIDR blocks and availability zones.

It can save you this CloudFormation template in a file with a .yaml or .yml extension. Then, you should utilize the AWS Administration Console, AWS CLI, or AWS SDKs to create a CloudFormation stack from the template. The stack creation course of will provision the VPC and subnets in accordance with the template.

Ensure you have the mandatory permissions to create VPCs and subnets in your AWS account. You need to use the AWS Administration Console’s CloudFormation service or the AWS CLI command aws cloudformation create-stack to create the stack from the template.

This instance assumes you will have already configured the AWS CLI with applicable credentials and the required permissions for creating VPCs and subnets.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments