Skip to content

Instantly share code, notes, and snippets.

@iMilnb
Last active April 23, 2017 13:27
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 iMilnb/f4eceddd3d4b45d645f22fd7f7cb69be to your computer and use it in GitHub Desktop.
Save iMilnb/f4eceddd3d4b45d645f22fd7f7cb69be to your computer and use it in GitHub Desktop.
Simple ASG (1:1) creation via Troposphere, providing a CloudFormation JSON template
from troposphere import Template, Ref, Parameter, Tags
from troposphere.autoscaling import LaunchConfiguration, AutoScalingGroup, Tag
t = Template()
params = {
'AmiId': 'Baked AMI Id',
'InstanceName': 'Name tag of the instance',
'SecurityGroup': 'Security Group' ,
'KeyName': 'SSH Key Name' ,
'InstanceType': 'Instance Type',
'EnvType': 'test',
'ScaleCapacity': 'Number of api servers to run',
'SubnetA': 'ASG Subnet A'
}
for p in params.keys():
vars()[p] = t.add_parameter(Parameter(
p,
Type = "String",
Description = params[p]
))
LaunchConfig = t.add_resource(LaunchConfiguration(
"LaunchConfiguration",
ImageId = Ref(AmiId),
SecurityGroups = [Ref(SecurityGroup)],
KeyName = Ref(KeyName),
InstanceType = Ref(InstanceType)
))
t.add_resource(AutoScalingGroup(
"AutoscalingGroup",
Tags=[
Tag("Environment", Ref(EnvType), True),
Tag("Name", Ref(InstanceName), True)
],
DesiredCapacity = Ref(ScaleCapacity),
LaunchConfigurationName=Ref(LaunchConfig),
MinSize = Ref(ScaleCapacity),
MaxSize = Ref(ScaleCapacity),
VPCZoneIdentifier=[Ref(SubnetA)],
))
print(t.to_json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment