Пример #1
0
 def test_bucket_template(self):
     AliasTarget("zone", "dnsname", True)
     AliasTarget(hostedzoneid="zone",
                 dnsname="dnsname",
                 evaluatetargethealth=True)
     AliasTarget(HostedZoneId="zone",
                 DNSName="dnsname",
                 EvaluateTargetHealth=True)
Пример #2
0
    def getTemplate(self):
        if self.elbName is not None:
            hostedZoneId=GetAtt(self.elbName,'CanonicalHostedZoneNameID')
            dnsName=GetAtt(self.elbName,'DNSName')
            aliasTarget=AliasTarget(hostedZoneId, dnsName)

            self.template.add_resource(RecordSetGroup(
            "DNS",
            HostedZoneName=Join(".", [ self.projectBaseURL, ""]),
            RecordSets=[
                RecordSet(
                    SetIdentifier=Join(" ", [ self.friendlyName, self.branch, self.projectBaseURL ] ),
                    Name=Join(" ", [ self.friendlyName, self.branch, self.projectBaseURL ] ),
                    Type="A",
                    AliasTarget=aliasTarget
                )
            ]))
        else:
            self.template.add_resource(RecordSetGroup(
            "DNS",
            HostedZoneName=Join(".", [ self.projectBaseURL, ""]),
            RecordSets=[
                RecordSet(
                    SetIdentifier=Join(" ", [ self.friendlyName, self.branch, self.projectBaseURL ] ),
                    Name=Join(" ", [ self.friendlyName, self.branch, self.projectBaseURL ] ),
                    Type="A",
                    ResourceRecords=[ GetAtt(self.launchConfigName, 'PublicIp')]
                )
            ]))

        return self.template
Пример #3
0
def create_record(name, route53_zone, route53_stack, target_elbv2,
                  elbv2_stack) -> None:
    """
    Create a new RecordResource with the given DNS Name pointing to the ELB

    :param str name:
    :param ecs_composex.route53.route53_zone.HostedZone route53_zone:
    :param ecs_composex.route53.route53_stack.XStack route53_stack:
    :param ecs_composex.elbv2.elbv2_stack.Elbv2 target_elbv2:
    :param ComposeXStack elbv2_stack:
    """
    if not target_elbv2.attributes_outputs:
        target_elbv2.init_outputs()
        target_elbv2.generate_outputs()
        add_outputs(elbv2_stack.stack_template, target_elbv2.outputs)
    lb_zone_id = target_elbv2.attributes_outputs[LB_DNS_ZONE_ID]
    lb_dns_name = target_elbv2.attributes_outputs[LB_DNS_NAME]
    add_parameters(
        route53_stack.stack_template,
        [lb_zone_id["ImportParameter"], lb_dns_name["ImportParameter"]],
    )
    route53_stack.Parameters.update({
        lb_zone_id["ImportParameter"].title:
        lb_zone_id["ImportValue"],
        lb_dns_name["ImportParameter"].title:
        lb_dns_name["ImportValue"],
    })
    elbv2_alias = AliasTarget(
        HostedZoneId=Ref(lb_zone_id["ImportParameter"]),
        DNSName=Ref(lb_dns_name["ImportParameter"]),
    )
    record_props = {
        "AliasTarget": elbv2_alias,
        "Region": Ref(AWS_REGION),
        "Type": "A",
        "Name": name,
    }
    if not keyisset("SetIdentifier", record_props):
        record_props["SetIdentifier"] = Ref(AWS_STACK_NAME)
    if route53_zone.cfn_resource:
        zone_id_attribute = GetAtt(route53_zone.cfn_resource,
                                   PUBLIC_DNS_ZONE_ID.return_value)
        record_props["HostedZoneId"] = zone_id_attribute
    elif route53_zone.mappings:
        zone_id_attribute = route53_zone.attributes_outputs[PUBLIC_DNS_ZONE_ID]
        record_props["HostedZoneId"] = zone_id_attribute["ImportValue"]
    cfn_resource = RecordSetType(
        f"elbv2{target_elbv2.logical_name}Route53{record_props['Type']}{NONALPHANUM.sub('', record_props['Name'])}"[:
                                                                                                                    128],
        **record_props,
    )
    if cfn_resource.title not in route53_stack.stack_template.resources:
        route53_stack.stack_template.add_resource(cfn_resource)
    if elbv2_stack.title not in route53_stack.DependsOn:
        route53_stack.DependsOn.append(elbv2_stack.title)
Пример #4
0
 def create_route53_records(self, load_balancer):
     self.t.add_resource(
         RecordSetType("ARecord",
                       AliasTarget=AliasTarget(
                           HostedZoneId=GetAtt(load_balancer,
                                               "CanonicalHostedZoneNameID"),
                           DNSName=GetAtt(load_balancer, "DNSName")),
                       HostedZoneId="Z2XJ10AKMCBNEF",
                       Comment="A Record Alias to ELB",
                       Name="loremipsum.tv17.co.uk.",
                       Type="A",
                       DependsOn="LoadBalancer"))
Пример #5
0
def create_private_dns_elb(template, hosted_zone, name, elb, cf_resource_name):
    dns_record = template.add_resource(RecordSetType(
        cf_resource_name,
        HostedZoneName=Join("", [hosted_zone, "."]),
        Comment="DNS name for my instance.",
        Name=Join(".", [name, hosted_zone, ""]),
        Type="A",
        AliasTarget=AliasTarget(GetAtt(elb, "CanonicalHostedZoneNameID"), GetAtt(elb, "CanonicalHostedZoneName")),
        DependsOn=elb
    ))

    return dns_record
Пример #6
0
                MinimumProtocolVersion=
                'TLSv1.1_2016',  # We might need to raise this
            ),
        ),
    ))

template.add_resource(
    RecordSetGroup(
        "DnsRecords",
        HostedZoneId=ImportValue(Join('-', [Ref(dns_stack), 'HostedZoneId'])),
        RecordSets=[
            RecordSet(
                Name=Ref(domain_name),
                Type='A',
                AliasTarget=AliasTarget(
                    HostedZoneId='Z2FDTNDATAQYW2',
                    DNSName=GetAtt(video_cdn, 'DomainName'),
                ),
            ),
            RecordSet(
                Name=Ref(domain_name),
                Type='AAAA',
                AliasTarget=AliasTarget(
                    HostedZoneId='Z2FDTNDATAQYW2',
                    DNSName=GetAtt(video_cdn, 'DomainName'),
                ),
            )
        ],
        Comment=Join('', ['Record for CloudFront in ',
                          Ref(AWS_STACK_NAME)]),
    ))
Пример #7
0
                                    ResponsePagePath='/404.html'),
            ],
        ),
    ))

template.add_resource(
    RecordSetGroup(
        'DnsRecords',
        Comment=Ref(AWS_STACK_NAME),
        HostedZoneId=ImportValue(Join('-', [Ref(dns_stack), 'HostedZoneId'])),
        RecordSets=[
            RecordSet(
                Name='robkenis.com',
                Type='A',
                AliasTarget=AliasTarget(
                    DNSName=GetAtt(cloudfront, 'DomainName'),
                    HostedZoneId='Z2FDTNDATAQYW2',
                ),
            ),
            RecordSet(
                Name='robkenis.com',
                Type='AAAA',
                AliasTarget=AliasTarget(
                    DNSName=GetAtt(cloudfront, 'DomainName'),
                    HostedZoneId='Z2FDTNDATAQYW2',
                ),
            ),
            RecordSet(
                Name='www.robkenis.com',
                Type='A',
                AliasTarget=AliasTarget(
                    DNSName=GetAtt(cloudfront, 'DomainName'),
Пример #8
0
                # ApiGateway 의 TTL 을 최대 10분으로 설정한다.
                MaxTTL=600,
            ),
            DefaultRootObject="index.html",
            Enabled=True,
            PriceClass="PriceClass_All",
            HttpVersion="http2",
        ),
    ))

template.add_resource(
    RecordSetGroup(
        "AssetsDNSName",
        HostedZoneName=Join("", [root_domain_name, "."]),
        Comment="Zone apex alias.",
        RecordSets=[
            RecordSet(
                Name=api_domain_name,
                Type="A",
                AliasTarget=AliasTarget(
                    # CloudFront 는 HostedZoneId 가 하나이다.
                    HostedZoneId="Z2FDTNDATAQYW2",
                    DNSName=GetAtt(distribution, "DomainName")),
            ),
        ],
    ))


def get():
    return template.to_yaml()
Пример #9
0
from troposphere import GetAtt, Join, Template
from troposphere.route53 import AliasTarget, RecordSetType, RecordSetGroup, RecordSet

t = Template()

myDNSRecord = t.add_resource(
    RecordSetGroup(
        "devdevopsdemoELBDNSARecord0",
        HostedZoneName=Join("", ["example.net", "."]),
        Comment="DNS Entry to point to the ELB for devopsdemo",
        RecordSets=[
            RecordSet(
                Name="devopsdemo.dev.example.net.",
                Type="A",
                AliasTarget=AliasTarget(
                    GetAtt("devdevopsdemoELB", "CanonicalHostedZoneNameID"),
                    GetAtt("devdevopsdemoELB", "CanonicalHostedZoneName"),
                ),
            ),
            RecordSet(
                Name="devopsdemo-dev.example.net.",
                Type="A",
                AliasTarget=AliasTarget(
                    GetAtt("devdevopsdemoELB", "CanonicalHostedZoneNameID"),
                    GetAtt("devdevopsdemoELB", "CanonicalHostedZoneName"),
                ),
            ),
        ],
    ))

print t.to_json()
Пример #10
0
    RecordSets = [
        RecordSet(
            Name = GetAtt(certificate_dns_record, "Name"),
            Type = GetAtt(certificate_dns_record, "Type"),
            TTL = "60",
            Weight = "1",
            SetIdentifier = Ref(origin_certificate),
            ResourceRecords = [
                GetAtt(certificate_dns_record, "Value")
            ]
        ),
        RecordSet(
            "origindnsrecord",
            AliasTarget = AliasTarget(
                DNSName = GetAtt(application_load_balancer, "DNSName"),
                EvaluateTargetHealth = False,
                HostedZoneId = GetAtt(application_load_balancer, "CanonicalHostedZoneID")
            ),
            Name = "origin.public.eu-west-1.weblox.io.",
            Type = "A",
            Weight = "1",
            SetIdentifier = "origin",
        )
    ]
)

template.add_resource(origin_certificate),
template.add_resource(origin_issued_certificate),
template.add_resource(certificate_dns_record)
template.add_resource(alb_record_set_group)
Пример #11
0
                        ErrorCachingMinTTL='0',
                        ErrorCode='504',
                    ),
                ],
            ),
            Tags=DefaultTags))

    cdnARecord = t.add_resource(
        RecordSetType("{}{}Adns".format(app_group_ansi,
                                        src_domain.replace('.', '0')),
                      HostedZoneName='{}.'.format(dns_domain),
                      Comment="{} domain record".format(cdn_domain),
                      Name='{}'.format(cdn_domain),
                      Type="A",
                      AliasTarget=AliasTarget(HostedZoneId=cfront_zone_id,
                                              DNSName=GetAtt(
                                                  cdnDistribution,
                                                  "DomainName"))))

    cdnAAAARecord = t.add_resource(
        RecordSetType("{}{}AAAAdns".format(app_group_ansi,
                                           src_domain.replace('.', '0')),
                      HostedZoneName='{}.'.format(dns_domain),
                      Comment="{} domain record".format(cdn_domain),
                      Name='{}'.format(cdn_domain),
                      Type="AAAA",
                      AliasTarget=AliasTarget(HostedZoneId=cfront_zone_id,
                                              DNSName=GetAtt(
                                                  cdnDistribution,
                                                  "DomainName"))))

    if domain_info['alt_sub'] != '':
Пример #12
0
template.add_resource(BasePathMapping(
    'ApiMapping',
    DomainName=Ref(domain_name),
    RestApiId=Ref(admin_api),
    Stage='v1'
))

template.add_resource(RecordSetGroup(
    "DnsRecords",
    HostedZoneId=ImportValue(Join('-', [Ref(dns_stack), 'HostedZoneId'])),
    RecordSets=[RecordSet(
        Name=Ref(domain_name),
        Type='A',
        AliasTarget=AliasTarget(
            HostedZoneId=GetAtt(api_domain_name, 'RegionalHostedZoneId'),
            DNSName=GetAtt(api_domain_name, 'RegionalDomainName'),
        ),
    ), RecordSet(
        Name=Ref(domain_name),
        Type='AAAA',
        AliasTarget=AliasTarget(
            HostedZoneId=GetAtt(api_domain_name, 'RegionalHostedZoneId'),
            DNSName=GetAtt(api_domain_name, 'RegionalDomainName'),
        ),
    )],
    Comment=Join('', ['Record for Api Gateway in ', Ref(AWS_STACK_NAME)]),
))

f = open("output/spunt_video_admin.json", "w")
f.write(template.to_json())
Пример #13
0
           AccessControl=PublicRead,
           WebsiteConfiguration=WebsiteConfiguration(
               RedirectAllRequestsTo=RedirectAllRequestsTo(
                   HostName=Ref(root_bucket)))))

record = t.add_resource(
    RecordSetGroup(
        'RecordSetGroup',
        HostedZoneName=Join("", [Ref(hostedzone), "."]),
        RecordSets=[
            RecordSet(Name=Ref(hostedzone),
                      Type='A',
                      AliasTarget=AliasTarget(
                          hostedzoneid=FindInMap('RegionMap',
                                                 Ref('AWS::Region'),
                                                 'S3hostedzoneID'),
                          dnsname=FindInMap('RegionMap', Ref('AWS::Region'),
                                            'websiteendpoint'),
                      )),
            RecordSet(Name=Join('.', ['www', Ref(hostedzone)]),
                      Type='CNAME',
                      TTL='900',
                      ResourceRecords=[GetAtt(www_bucket, 'DomainName')]),
        ]))

t.add_output(
    Output("BucketName",
           Value=Ref(root_bucket),
           Description="Name of S3 bucket to hold website content"))

#print(t.to_json())
Пример #14
0
            AcmCertificateArn   = Ref(ssl_certificate),
            SslSupportMethod    = 'sni-only'
        ),
        DefaultRootObject   = 'index.html'
    )
))

dns_record = t.add_resource(RecordSetType(
    'aliasDnsRecord',
    Condition = 'zoneIdSet',
    HostedZoneId = Ref(zone_id),
    Name = Join('', [Ref(domain_name), '.']),
    Type = 'A',
    AliasTarget = AliasTarget(
        # as per http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget.html
        HostedZoneId = 'Z2FDTNDATAQYW2',
        DNSName = GetAtt('myDistribution', 'DomainName'),
        EvaluateTargetHealth = False
    )
))

# Outputs
t.add_output([
    # find by Id in console
    Output('DistributionId', Value=Ref(my_distribution)),
    # Point CNAME here
    Output('DistributionName',
        Value=Join('', ['http://', GetAtt('myDistribution', 'DomainName')])),

])

print(t.to_json())
Пример #15
0
def create_cloudfront_template():
    template = Template()

    cname = template.add_parameter(
        parameter=Parameter(title='Cname', Type='String'))

    acm_certificate_arn = template.add_parameter(
        parameter=Parameter(title='AcmCertificateArn', Type='String'))

    host_zone_id = template.add_parameter(
        parameter=Parameter(title='HostZoneId', Type='String'))

    bucket = template.add_resource(
        resource=Bucket(title='SampleBucket',
                        BucketName=Sub('sample-bucket-${AWS::AccountId}')))

    identity = template.add_resource(resource=CloudFrontOriginAccessIdentity(
        title='SampleOriginAccessIdentity',
        CloudFrontOriginAccessIdentityConfig=
        CloudFrontOriginAccessIdentityConfig(Comment='sample')))

    template.add_resource(resource=BucketPolicy(
        title='SampleBucketPolicy',
        Bucket=Ref(bucket),
        PolicyDocument={
            'Statement': [{
                'Action':
                's3:GetObject',
                'Effect':
                'Allow',
                'Resource':
                Join(delimiter='/', values=[GetAtt(bucket, 'Arn'), '*']),
                'Principal': {
                    'CanonicalUser':
                    GetAtt(logicalName=identity, attrName='S3CanonicalUserId')
                }
            }]
        }))

    distribution = template.add_resource(resource=Distribution(
        title='SampleDistribution',
        DistributionConfig=DistributionConfig(
            Aliases=[Ref(cname)],
            # CustomErrorResponses=[
            #     CustomErrorResponse(
            #         ErrorCode=403,
            #         ResponseCode=200,
            #         ResponsePagePath='/404.html',
            #         ErrorCachingMinTTL=30
            #     )
            # ],
            DefaultCacheBehavior=DefaultCacheBehavior(
                ForwardedValues=ForwardedValues(QueryString=True, ),
                TargetOriginId=Sub('S3-${' + bucket.title + '}'),
                ViewerProtocolPolicy='redirect-to-https',
            ),
            # DefaultRootObject='index.html',
            Enabled=True,
            Origins=[
                Origin(Id=Sub('S3-${' + bucket.title + '}'),
                       DomainName=Sub('${' + bucket.title +
                                      '}.s3.amazonaws.com'),
                       S3OriginConfig=S3OriginConfig(OriginAccessIdentity=Sub(
                           'origin-access-identity/cloudfront/${' +
                           identity.title + '}')))
            ],
            ViewerCertificate=ViewerCertificate(AcmCertificateArn=Ref(
                acm_certificate_arn),
                                                SslSupportMethod='sni-only'))))

    template.add_resource(resource=RecordSetType(
        title='SampleRecordSet',
        AliasTarget=AliasTarget(HostedZoneId='Z2FDTNDATAQYW2',
                                DNSName=GetAtt(logicalName=distribution,
                                               attrName='DomainName')),
        HostedZoneId=Ref(host_zone_id),
        Name=Ref(cname),
        Type='A'))

    with open('./cloudfront.yml', mode='w') as file:
        file.write(template.to_yaml())
Пример #16
0
        ViewerCertificate=ViewerCertificate(
            AcmCertificateArn=Ref(cloudfront_certificate),
            SslSupportMethod='sni-only',
            MinimumProtocolVersion='TLSv1.1_2016',  # We might need to raise this
        ),
    ),
))

template.add_resource(RecordSetGroup(
    "DnsRecords",
    HostedZoneId=ImportValue(Join('-', [Ref(dns_stack), 'HostedZoneId'])),
    RecordSets=[RecordSet(
        Name=Ref(domain_name),
        Type='A',
        AliasTarget=AliasTarget(
            HostedZoneId='Z2FDTNDATAQYW2',
            DNSName=GetAtt(public_distribution, 'DomainName'),
        ),
    ), RecordSet(
        Name=Ref(domain_name),
        Type='AAAA',
        AliasTarget=AliasTarget(
            HostedZoneId='Z2FDTNDATAQYW2',
            DNSName=GetAtt(public_distribution, 'DomainName'),
        ),
    )],
    Comment=Join('', ['Record for CloudFront in ', Ref(AWS_STACK_NAME)]),
))

template.add_output(Output(
    'FrontendBucket',
    Description='Name of the frontend bucket',
                                 ]
                             ]
                         },
                         "Principal": "*"
                     }]
                 }))

# prepares DNS records depending on redirect direction
if www_to_root:
    record_sets = [
        RecordSet(
            Name=Join("", [Ref(HostedZoneName), "."]),
            Type="A",
            AliasTarget=AliasTarget(
                FindInMap("RegionMap", "cloudfront", "hostedzoneID"),
                Join(
                    "",
                    [GetAtt(StaticSiteBucketDistribution, "DomainName"), "."]),
            )),
        RecordSet(Name=Join("", ["www.", Ref(HostedZoneName), "."]),
                  Type="A",
                  AliasTarget=AliasTarget(
                      FindInMap("RegionMap", Ref("AWS::Region"),
                                "hostedzoneID"),
                      FindInMap("RegionMap", Ref("AWS::Region"),
                                "websiteendpoint"))),
    ]
else:
    record_sets = [
        RecordSet(Name=Join("", [Ref(HostedZoneName), "."]),
                  Type="A",
                  AliasTarget=AliasTarget(
Пример #18
0
    DomainName=Ref(domain_name),
    DomainValidationOptions=[DomainValidationOption(
        DomainName=Ref(domain_name),
        ValidationDomain=ImportValue(Join('-', [Ref(dns_stack), 'HostedZoneName'])),
    )],
    ValidationMethod='DNS',
))

template.add_resource(RecordSetGroup(
    "DnsRecords",
    HostedZoneId=ImportValue(Join('-', [Ref(dns_stack), 'HostedZoneId'])),
    RecordSets=[RecordSet(
        Name=Ref(domain_name),
        Type='A',
        AliasTarget=AliasTarget(
            HostedZoneId='Z2FDTNDATAQYW2',
            DNSName=Ref(cognito_domain_name),
        ),
    ), RecordSet(
        Name=Ref(domain_name),
        Type='AAAA',
        AliasTarget=AliasTarget(
            HostedZoneId='Z2FDTNDATAQYW2',
            DNSName=Ref(cognito_domain_name),
        ),
    )],
    Comment=Join('', ['Record for Cognito in ', Ref(AWS_STACK_NAME)]),
    Condition=DOMAIN_IS_CREATED,
))

user_pool = template.add_resource(UserPool(
    'UserPool',