Simplify AWS Infrastructure Deployment with CloudFormation

Simplify AWS Infrastructure Deployment with CloudFormation

Are you tired of manually configuring your AWS infrastructure? Say goodbye to tedious setup processes and hello to efficiency with AWS CloudFormation!

CloudFormation allows you to define your infrastructure as code using simple YAML or JSON templates. With just a few lines of code, you can provision and manage a wide range of AWS resources, from VPCs and subnets to EC2 instances and S3 buckets.

By using CloudFormation, you ensure consistency and repeatability in your infrastructure deployments. No more manual errors or configuration drifts – simply update your template and let CloudFormation handle the rest.

So why CloudFormation? Because it streamlines your AWS infrastructure management, saving you time and effort while ensuring reliability and scalability. Say hello to automated infrastructure provisioning with CloudFormation today!

AWSTemplateFormatVersion: "2010-09-09"
Description: "This is a combo of VPC + Subnet + Ec2 and S3"

Metadata: 
  AWS::CloudFormation::Interface: 
    ParameterGroups: 
      - 
        Label: 
          default: "Amazon EC2 "
        Parameters: 
          - EC2AMIID
          - InstanceTypeParameter
      - 
        Label: 
          default: "Amazon VPC"
        Parameters: 
          - VpcCIDR
          - PublicSubnetCIDR
          - PrivateSubnetCIDR


Parameters:
  VpcCIDR:
    Description: Please enter the IP range (CIDR notation) for this VPC
    Type: String
    Default: 10.0.0.0/16

  PublicSubnetCIDR:
    Description: Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone
    Type: String
    Default: 10.0.1.0/24

  PrivateSubnetCIDR:
    Description: Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone
    Type: String
    Default: 10.0.2.0/24

  EC2AMIID:
    Type: String
    Default: ami-029e4db491be76287
    AllowedValues:
      - ami-029e4db491be76287
      - ami-0705384c0b33c194c
    Description: Select the AMI ID

  InstanceTypeParameter:
    Type: String
    Default: t3.micro
    AllowedValues:
      - t3.micro
      - t2.micro
      - m1.small
      - m1.large
    Description: Enter t2.micro, m1.small, or m1.large. Default is t3.micro.

Resources:
  ProdVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: !Ref VpcCIDR
      EnableDnsSupport: true
      EnableDnsHostnames: true
      Tags:
        - Key: Name
          Value: Prod-VPC

  PublicSubnet:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref ProdVPC
      AvailabilityZone: !Select [ 0, !GetAZs '' ]
      CidrBlock: !Ref PublicSubnetCIDR
      MapPublicIpOnLaunch: true
      Tags:
        - Key: Name
          Value: PublicSubnet

  PrivateSubnet:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref ProdVPC
      AvailabilityZone: !Select [ 1, !GetAZs '' ]
      CidrBlock: !Ref PrivateSubnetCIDR
      MapPublicIpOnLaunch: false
      Tags:
        - Key: Name
          Value: PrivateSubnet

  PublicRouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref ProdVPC
      Tags:
        - Key: Name
          Value: PublicRoutes

  PrivateRouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref ProdVPC
      Tags:
        - Key: Name
          Value: PrivateRoutes

  PublicSubnetRouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId: !Ref PublicRouteTable
      SubnetId: !Ref PublicSubnet

  PrivateSubnetRouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId: !Ref PrivateRouteTable
      SubnetId: !Ref PrivateSubnet

  PublicInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !Ref EC2AMIID
      InstanceType: !Ref InstanceTypeParameter
      NetworkInterfaces:
        - AssociatePublicIpAddress: true
          DeviceIndex: 0
          DeleteOnTermination: true
          SubnetId: !Ref PublicSubnet
      Tags:
        - Key: Name
          Value: PublicInstance

  PrivateInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !Ref EC2AMIID
      InstanceType: !Ref InstanceTypeParameter
      NetworkInterfaces:
        - AssociatePublicIpAddress: false
          DeviceIndex: 0
          DeleteOnTermination: true
          SubnetId: !Ref PrivateSubnet
      Tags:
        - Key: Name
          Value: PrivateInstance
        

#AWS #CloudFormation #InfrastructureAsCode

要查看或添加评论,请登录

Bhupendra Maurya的更多文章

  • Amazon ECS (Elastic Container Service)

    Amazon ECS (Elastic Container Service)

    AWS ECS stands for Amazon Elastic Container Service. It is a fully managed container orchestration service provided by…

    1 条评论
  • Nonrelational Databases

    Nonrelational Databases

    Key-value databases Key-value databases logically store data in a single table. Within the table, the values are…

  • Subnets and Network Access Control Lists

    Subnets and Network Access Control Lists

    Subnets A subnet is a section of a VPC in which you can group resources based on security or operational needs. Subnets…

  • ?? Extending Root Volume on an AWS EC2 Instance ??

    ?? Extending Root Volume on an AWS EC2 Instance ??

    Today, I faced a critical situation with my AWS EC2 instance - I ran out of storage space on the root volume! ?? Here's…

  • AWS VPC Setup with Terraform!

    AWS VPC Setup with Terraform!

    ?? I'm excited to share a recent project where I leveraged Terraform to automate the creation of a secure and scalable…

  • Amazon Ec2 Lifecycle

    Amazon Ec2 Lifecycle

    Amazon EC2 (Elastic Compute Cloud) lifecycle refers to the various states and transitions that an EC2 instance…

  • Comparing Purchasing Options

    Comparing Purchasing Options

    1. On-Demand Instances With On-Demand Instances, you pay for compute capacity by the hour or by the second depending on…

    1 条评论
  • AWS Networking

    AWS Networking

    #Subnet A subnet, or subnetwork, is a smaller network inside of a larger network. A subnet consists of a smaller…

  • Migrating an E-commerce startup

    Migrating an E-commerce startup

    #Scenario: A growing e-commerce startup is experiencing significant traffic spikes during peak sales seasons. Their…

  • Docker volumes & Bind Mount

    Docker volumes & Bind Mount

    To list all the volumes 2. To create a new volume 3.

    3 条评论

社区洞察

其他会员也浏览了