本文整理汇总了Python中troposphere.autoscaling.AutoScalingGroup.DependsOn方法的典型用法代码示例。如果您正苦于以下问题:Python AutoScalingGroup.DependsOn方法的具体用法?Python AutoScalingGroup.DependsOn怎么用?Python AutoScalingGroup.DependsOn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类troposphere.autoscaling.AutoScalingGroup
的用法示例。
在下文中一共展示了AutoScalingGroup.DependsOn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_microservice_asg
# 需要导入模块: from troposphere.autoscaling import AutoScalingGroup [as 别名]
# 或者: from troposphere.autoscaling.AutoScalingGroup import DependsOn [as 别名]
#.........这里部分代码省略.........
template.mappings[name] = {
region: {'instanceType': instance_type, 'ami': ami, 'profile': instance_profile}
}
if not availability_zones:
availability_zones = _all_az(region)
if load_balancer:
security_groups.append(template.add_resource(ec2.SecurityGroup(
"InstanceSecurityGroup" + name,
GroupDescription="Enable access from ELB",
SecurityGroupIngress=[
ec2.SecurityGroupRule(
IpProtocol='tcp',
FromPort=load_balancer['elb'].Listeners[0].InstancePort,
ToPort=load_balancer['elb'].Listeners[0].InstancePort,
SourceSecurityGroupId=Ref(load_balancer_security_group)
),
],
VpcId=vpc_id
)))
if not creation_policy:
creation_policy = _default_creation_policy(name)
if not update_policy:
update_policy = _default_update_policy()
security_group_refs = [Ref(sg) for sg in security_groups]
asg_name = "AutoscalingGroup" + name
lc_name = "LaunchConfiguration" + name
lc = LaunchConfiguration(
lc_name,
UserData=Base64(Join('', [
"#!/bin/bash -ex\n",
"# redirect output to syslog\n",
"exec 1> >(logger -s -t user-data) 2>&1\n",
"# running cfn-init\n",
"/usr/local/bin/cfn-init --stack ", Ref("AWS::StackName"), " --resource {}".format(lc_name), " --region ",
Ref("AWS::Region"), "\n",
"echo \"cfn-init finished\"\n",
"printf '%b\n' \"$(cat /home/ubuntu/application.properties)\"\n",
"# restart services\n",
"service supervisor restart\n",
"echo \"restarting services\"\n",
"# wait until microservice is ready\n",
"until $(curl --output /dev/null --silent --head --fail http://localhost:{}/health); do\n".format(
instance_port),
" printf '.'\n",
" sleep 5\n",
"done\n"
"echo \"springboot is up\"\n",
"# signal asg\n"
"cfn-signal -e 0",
" --resource {}".format(asg_name),
" --stack ", Ref("AWS::StackName"),
" --region ", Ref("AWS::Region"), "\n"
])),
ImageId=FindInMap(name, Ref("AWS::Region"), 'ami'),
KeyName=key_name,
SecurityGroups=security_group_refs,
InstanceType=FindInMap(name, Ref("AWS::Region"), 'instanceType'),
IamInstanceProfile=Ref(instance_profile)
)
if metadata:
lc.Metadata = metadata
lc = template.add_resource(lc)
if not desired_capacity:
desired_capacity = max_size
if not subnets:
subnets = _get_vpc_subnets(vpc_id, region)
asg = AutoScalingGroup(
asg_name,
DesiredCapacity=desired_capacity,
Tags=tags,
LaunchConfigurationName=Ref(lc),
MinSize=min_size,
MaxSize=max_size,
LoadBalancerNames=[Ref(load_balancer['elb'])] if load_balancer else None,
HealthCheckGracePeriod=60,
AvailabilityZones=availability_zones,
HealthCheckType="EC2" if not load_balancer else "ELB",
VPCZoneIdentifier=subnets,
CreationPolicy=creation_policy,
UpdatePolicy=update_policy
)
if depends_on:
asg.DependsOn = depends_on
asg = template.add_resource(asg)
return {
'asg': asg,
'lc': lc,
'security_groups': security_groups
}