Skip to content

Instantly share code, notes, and snippets.

@imadityac
Forked from nickpad/cloudformation.json
Created May 28, 2020 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imadityac/52b7035f87db2b9d07d84d105ee32eb1 to your computer and use it in GitHub Desktop.
Save imadityac/52b7035f87db2b9d07d84d105ee32eb1 to your computer and use it in GitHub Desktop.
Example cloudformation template for auto scaling deploys
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Auto scaling deploy example",
"Parameters": {
"AvailabilityZone": {
"Type": "String",
"Default": "us-west-1a"
},
"ImageId": {
"Type": "String"
}
},
"Resources": {
"VPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16",
"EnableDnsSupport": true,
"EnableDnsHostnames": true
}
},
"InternetGateway": {
"Type": "AWS::EC2::InternetGateway",
"Properties": {}
},
"VPCGatewayAttachment": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"InternetGatewayId": {
"Ref": "InternetGateway"
},
"VpcId": {
"Ref": "VPC"
}
}
},
"PublicSubnet": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Ref": "AvailabilityZone"
},
"CidrBlock": "10.0.0.0/24",
"VpcId": {
"Ref": "VPC"
},
"Tags": [
{
"Key": "Name",
"Value": "Public"
}
]
}
},
"PublicRouteTable": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"Tags": [
{
"Key": "Name",
"Value": "Public"
}
]
}
},
"OutboundConnectionRoute": {
"Type": "AWS::EC2::Route",
"Properties": {
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "InternetGateway"
},
"RouteTableId": {
"Ref": "PublicRouteTable"
}
}
},
"PublicSubnetRouteTableAssociation": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {
"Ref": "PublicRouteTable"
},
"SubnetId": {
"Ref": "PublicSubnet"
}
}
},
"WebServerSG": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"GroupDescription": "Allows inbound http traffic",
"SecurityGroupIngress": [
{
"CidrIp": "0.0.0.0/0",
"FromPort": 80,
"IpProtocol": "tcp",
"ToPort": 80
}
],
"Tags": [
{
"Key": "Name",
"Value": "http"
}
]
}
},
"LoadBalancer": {
"Type": "AWS::ElasticLoadBalancing::LoadBalancer",
"Properties": {
"LoadBalancerName": "LoadBalancer",
"Listeners": [
{
"InstancePort": 80,
"InstanceProtocol": "HTTP",
"LoadBalancerPort": 80,
"Protocol": "HTTP"
}
],
"Scheme": "internet-facing",
"SecurityGroups": [
{
"Ref": "WebServerSG"
}
],
"Subnets": [
{
"Ref": "PublicSubnet"
}
]
}
},
"AppLaunchConfiguration": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"AssociatePublicIpAddress": true,
"ImageId": {
"Ref": "ImageId"
},
"InstanceType": "t2.micro",
"SecurityGroups": []
},
"DependsOn": "VPCGatewayAttachment"
},
"AppASG": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"AvailabilityZones": [
{
"Ref": "AvailabilityZone"
}
],
"DesiredCapacity": 1,
"LaunchConfigurationName": {
"Ref": "AppLaunchConfiguration"
},
"LoadBalancerNames": [
{
"Ref": "LoadBalancer"
}
],
"MaxSize": 2,
"MinSize": 1,
"VPCZoneIdentifier": [
{
"Ref": "PublicSubnet"
}
]
},
"UpdatePolicy": {
"AutoScalingRollingUpdate": {
"MinInstancesInService": 1
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment