Simplify AWS Infrastructure Deployment with CloudFormation
Bhupendra Maurya
Software Developer | Web Developer | React | Angular | JavaScript | Typescript | Node | AWS | HTML/CSS | Passionate about solving problems and constantly learning to enhance my skills in full-stack development
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