Skip to content

Instantly share code, notes, and snippets.

@ksnabb
Last active November 16, 2017 20:28
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 ksnabb/99c14e01ca91091f8e5d66ad07ebd1a8 to your computer and use it in GitHub Desktop.
Save ksnabb/99c14e01ca91091f8e5d66ad07ebd1a8 to your computer and use it in GitHub Desktop.
ec2_role = stack.add_resource(
Role(
'WebappInstanceRole',
AssumeRolePolicyDocument=Policy(
Statement=[Statement(
Effect=Allow,
Principal=Principal('Service', ['ec2.amazonaws.com']),
Action=[AssumeRole]
)]
),
ManagedPolicyArns=['arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforAWSCodeDeploy'],
Path='/webapp/',
RoleName='WebappRole'
)
)
instance_profile = stack.add_resource(
InstanceProfile(
'WebappInstanceProfile',
Path='/webapp/',
Roles=[Ref(ec2_role)],
InstanceProfileName='Webapp'
)
)
launch_configuration = stack.add_resource(
LaunchConfiguration(
'LaunchConfiguration',
AssociatePublicIpAddress=True,
IamInstanceProfile=Ref(instance_profile),
ImageId='ami-acd005d5',
InstanceType='t2.nano',
KeyName='test',
SecurityGroups=[Ref(app_security_group)],
UserData=userdata.from_file('./aws/userdata.sh')
)
)
auto_scaling_group = stack.add_resource(AutoScalingGroup(
'AutoscalingGroup',
DesiredCapacity=2,
HealthCheckType='ELB',
HealthCheckGracePeriod=150,
LaunchConfigurationName=Ref(launch_configuration),
LoadBalancerNames=[Ref(elb)],
MaxSize=4,
MinSize=2,
VPCZoneIdentifier=[Ref(public_subnet1), Ref(public_subnet2)]
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment