Exemplo n.º 1
0
def create_autoscaling_group_resource(template, api_instance_count_parameter,
                                      launch_template_resource):
    return template.add_resource(
        autoscaling.AutoScalingGroup(
            'AutoScalingGroup',
            DesiredCapacity=Ref(api_instance_count_parameter),
            MinSize=Ref(api_instance_count_parameter),
            MaxSize=Ref(api_instance_count_parameter),
            LaunchTemplate=autoscaling.LaunchTemplateSpecification(
                LaunchTemplateId=Ref(launch_template_resource),
                Version=GetAtt(launch_template_resource,
                               'LatestVersionNumber')),
            AvailabilityZones=['eu-west-1a', 'eu-west-1b', 'eu-west-1c']))
Exemplo n.º 2
0
            MinimumHealthyPercent=0,
            MaximumPercent=100
        ),
        DesiredCount=Ref(scheduler_task_count),
        LaunchType='EC2'
    )
)

autoscaling_group = template.add_resource(
    autoscaling.AutoScalingGroup(
        'AutoScalingGroup',
        DesiredCapacity=Ref(api_instance_count),
        MinSize=Ref(api_instance_count),
        MaxSize=Ref(api_instance_count),
        LaunchTemplate=autoscaling.LaunchTemplateSpecification(
            LaunchTemplateId=Ref(launch_template),
            Version=GetAtt(launch_template, 'LatestVersionNumber')
        ),
        AvailabilityZones=['eu-west-1a', 'eu-west-1b', 'eu-west-1c']
    )
)

# Create the users.
api_user = template.add_resource(
    iam.User(
        'ApiUser',
        UserName=Ref(api_user_name),
        Policies=[
            iam.Policy(
                PolicyName='ApiUserPolicy',
                PolicyDocument={
                    'Version': '2012-10-17',
Exemplo n.º 3
0
Arquivo: ac3.py Projeto: ghac3/cfwp
                                    DefaultActions=[
                                        elasticloadbalancingv2.Action(
                                            Type="forward",
                                            TargetGroupArn=Ref('Tg'))
                                    ]))

# This is the ASG creation. The AvailabilityZones function didn't work for me due to some weird CF error about subnets.
# Since it's generally just a subset of VPCZoneIndentifier it should be ok to omit. I'd probably look into it more if
# I was serious about making a template for actual use.
asg = template.add_resource(
    autoscaling.AutoScalingGroup(
        "WordPressASG",
        DependsOn='WordPressAsgLaunchTemplate',
        TargetGroupARNs=[Ref('Tg')],
        LaunchTemplate=autoscaling.LaunchTemplateSpecification(
            LaunchTemplateId=Ref(lc),
            Version=GetAtt('WordPressAsgLaunchTemplate',
                           'LatestVersionNumber')),
        Cooldown=360,
        MinSize=If(
            'IsProd', '2',
            Ref('pAsgMinSize')),  # Dev gets 1 but we need 2 for HA in Prod
        MaxSize=If('IsProd', Ref('pAsgMaxSize'),
                   '1'),  # Dev gets max=1 but max=5 for Prod.
        #   AvailabilityZones=If('IsProd', [Ref('pVPCAvailabilityZone1'), Ref('pVPCAvailabilityZone2')], [Ref('pVPCAvailabilityZone1')]),
        HealthCheckType="EC2",
        MetricsCollection=[
            autoscaling.MetricsCollection(Granularity='1Minute')
        ],
        VPCZoneIdentifier=[Ref('pSubnet1'), Ref('pSubnet2')],
        Tags=autoscaling.Tags(Name=Join(
            '_', ['WordPressASG', Ref('AWS::StackName')]),