-
-
Save victoremmanuel/39a5ff32d5c670d02fe33c143b3c5bf8 to your computer and use it in GitHub Desktop.
Example cloudformation template for auto scaling deploys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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