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
def dns(self, host, zone, ttl=3600): if not zone.endswith('.'): zone = zone + '.' self.template.add_resource( RecordSetGroup( ("RSG" + hashlib.sha1(zone + host).hexdigest())[:10], Comment=Ref("AWS::StackName"), HostedZoneName=zone, RecordSets=[ RecordSet(Name="%s.%s" % (host, zone), Type="CNAME", ResourceRecords=[GetAtt("ELB", "DNSName")], TTL=ttl) ]))
)) myDNSRecord = t.add_resource( RecordSetGroup( "myDNSRecord", HostedZoneName=Join("", [Ref(hostedzone), "."]), Comment= "Contrived example to redirect to aws.amazon.com 75% of the time " "and www.amazon.com 25% of the time.", RecordSets=[ RecordSet( SetIdentifier=Join(" ", [Ref("AWS::StackName"), "AWS"]), Name=Join("", [ Ref("AWS::StackName"), ".", Ref("AWS::Region"), ".", Ref(hostedzone), "." ]), Type="CNAME", TTL="900", ResourceRecords=["aws.amazon.com"], Weight="3", ), RecordSet( SetIdentifier=Join(" ", [Ref("AWS::StackName"), "Amazon"]), Name=Join("", [ Ref("AWS::StackName"), ".", Ref("AWS::Region"), ".", Ref(hostedzone), "." ]), Type="CNAME", TTL="900", ResourceRecords=["www.amazon.com"],
}, "/*" ] ] }, "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), "."]),
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(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)]), ))
LoadBalancerPort="80", InstancePort="80", Protocol="HTTP", InstanceProtocol="HTTP" ) ], LoadBalancerName=Join("-",[Ref("AWS::StackName"),"ELB"]), Instances=[Ref(EC2Instance1), Ref(EC2Instance2) ], #DependsOn=["EC2Instance1", "EC2Instance2"] DependsOn=["Wait4Instance"] )) PublicRecords=[ RecordSet( Name=Join("",[ "demo.", Ref(HostedZone), "."]), Type="CNAME", TTL="400", ResourceRecords=[GetAtt("PublicLoadBalancer","DNSName")] ) ] PublicRecordSet=t.add_resource(RecordSetGroup( "PublicRecordSet", HostedZoneName=Join("",[Ref(HostedZone),"."]), Comment="Public Record sets", RecordSets=PublicRecords )) t.add_output([ Output( "InstanceId", Description="InstanceId of the newly created EC2 instance",
# 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()
ResponseCode=200, 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(
# # HostedZoneId = GetAtt(application_load_balancer, "CanonicalHostedZoneID") # # ), # Name = "origin.public.eu-west-1.weblox.io", # Type = "A", # TTL = "1" # ) alb_record_set_group = RecordSetGroup( region.replace("-", "") + "ecsliveorigindnsrecordsetgroup", HostedZoneId = hosted_zone_id, 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",
PriceClass='PriceClass_100', 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',
'_ccfe3690ea1cbc3f70ac9330debed77d.admin.spunt.be.': '_cd81118a1eddc7ee8e96a5d138582443.mzlfeqexyx.acm-validations.aws.', } template = Template(Description='Spunt.be validation records') dns_stack = template.add_parameter( Parameter( 'DnsStack', Type=constants.STRING, Default='spunt-punt-be-dns', )) _hosted_zone_id = ImportValue(Join('-', [Ref(dns_stack), 'HostedZoneId'])) template.add_resource( RecordSetGroup('ValidationRecords', HostedZoneId=_hosted_zone_id, Comment='Validation records for ACM', RecordSets=list( map( lambda name: RecordSet( Name=name, Type='CNAME', TTL=900, ResourceRecords=[RECORDS[name]], ), RECORDS.keys())))) f = open("output/validation_records.json", "w") f.write(template.to_json())
)) 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())
BucketName=Join('.', ['www', Ref(hostedzone)]), 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"))
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()
"Certificate", 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(