Last active
November 16, 2017 20:28
-
-
Save ksnabb/99c14e01ca91091f8e5d66ad07ebd1a8 to your computer and use it in GitHub Desktop.
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
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