選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

Route 53 範本程式碼片段

焦點模式
Route 53 範本程式碼片段 - AWS CloudFormation

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

篩選條件查看

使用託管區域名稱或 ID 的 Amazon Route 53 資源紀錄集

當您建立 Amazon Route 53 資源記錄集時,您必須指定要新增該記錄集的託管區域。CloudFormation 提供兩種指定託管區域的方式:

  • 您可以使用 HostedZoneId 屬性來明確指定託管區域。

  • 您可以使用 HostedZoneName 屬性讓 CloudFormation 尋找託管區域。如果您使用 HostedZoneName 屬性,而且有多個託管區域具有相同的名稱,CloudFormation 不會建立堆疊。

使用 HostedZoneId 新增 RecordSet

此範例新增了 Amazon Route 53 資源記錄集,其中包含mysite.example.com使用 HostedZoneId 屬性指定託管區域的網域名稱SPF記錄。

JSON

"myDNSRecord" : { "Type" : "AWS::Route53::RecordSet", "Properties" : { "HostedZoneId" : "Z3DG6IL3SJCGPX", "Name" : "mysite.example.com.", "Type" : "SPF", "TTL" : "900", "ResourceRecords" : [ "\"v=spf1 ip4:192.168.0.1/16 -all\"" ] } }

YAML

myDNSRecord: Type: AWS::Route53::RecordSet Properties: HostedZoneId: Z3DG6IL3SJCGPX Name: mysite.example.com. Type: SPF TTL: '900' ResourceRecords: - '"v=spf1 ip4:192.168.0.1/16 -all"'

使用 HostedZoneName 新增 RecordSet

此範例使用 HostedZoneName 屬性來指定託管區域,為網域名稱 "mysite.example.com" 新增 Amazon Route 53 資源紀錄集。

JSON

"myDNSRecord2" : { "Type" : "AWS::Route53::RecordSet", "Properties" : { "HostedZoneName" : "example.com.", "Name" : "mysite.example.com.", "Type" : "A", "TTL" : "900", "ResourceRecords" : [ "192.168.0.1", "192.168.0.2" ] } }

YAML

myDNSRecord2: Type: AWS::Route53::RecordSet Properties: HostedZoneName: example.com. Name: mysite.example.com. Type: A TTL: '900' ResourceRecords: - 192.168.0.1 - 192.168.0.2

使用 RecordSetGroup 設定加權資源紀錄集

此範例使用 AWS::Route53::RecordSetGroup 設定 "example.com" 的兩個 CNAME 記錄。託管區域。RecordSets 屬性包含 "mysite.example.com" DNS 名稱的 CNAME 記錄集。每一個記錄集都包含識別碼 (SetIdentifier) 和權重 (Weight)。路由至資源的網際網路流量比例是根據下列計算:

  • Frontend One: 140/(140+60) = 140/200 = 70%

  • Frontend Two: 60/(140+60) = 60/200 = 30%

如需有關加權資源記錄集的詳細資訊,請參閱《Amazon Route 53 開發人員指南》中的加權路由

JSON

"myDNSOne" : { "Type" : "AWS::Route53::RecordSetGroup", "Properties" : { "HostedZoneName" : "example.com.", "Comment" : "Weighted RR for my frontends.", "RecordSets" : [ { "Name" : "mysite.example.com.", "Type" : "CNAME", "TTL" : "900", "SetIdentifier" : "Frontend One", "Weight" : "140", "ResourceRecords" : ["example-ec2.amazonaws.com"] }, { "Name" : "mysite.example.com.", "Type" : "CNAME", "TTL" : "900", "SetIdentifier" : "Frontend Two", "Weight" : "60", "ResourceRecords" : ["example-ec2-larger.amazonaws.com"] } ] } }

YAML

myDNSOne: Type: AWS::Route53::RecordSetGroup Properties: HostedZoneName: example.com. Comment: Weighted RR for my frontends. RecordSets: - Name: mysite.example.com. Type: CNAME TTL: '900' SetIdentifier: Frontend One Weight: '140' ResourceRecords: - example-ec2.amazonaws.com - Name: mysite.example.com. Type: CNAME TTL: '900' SetIdentifier: Frontend Two Weight: '60' ResourceRecords: - example-ec2-larger.amazonaws.com

使用 RecordSetGroup 設定別名資源紀錄集

下列範例使用 AWS::Route53::RecordSetGroup 來設定名為 example.com 的別名資源記錄集,以將流量路由至 ELB 第 1 版 負載平衡器 (Classic Load Balancer) 以及第 2 版負載平衡器 (Application Load Balancer 或 Network Load Balancer)。AliasTarget 屬性myELBLoadBalancer會使用GetAtt內部 函數指定 的託管區域 ID 和 DNS 名稱。 會GetAtt擷取myELB資源的不同屬性,取決於您要將流量路由到第 1 版或第 2 版負載平衡器:

  • 第 1 版負載平衡器:CanonicalHostedZoneNameIDDNSName

  • 第 2 版負載平衡器:CanonicalHostedZoneIDDNSName

如需有關別名資源記錄集的詳細資訊,請參閱《Route 53 開發人員指南》中的選擇別名或非別名記錄

適用於第 1 版負載平衡器的 JSON

"myELB" : { "Type" : "AWS::ElasticLoadBalancing::LoadBalancer", "Properties" : { "AvailabilityZones" : [ "us-east-1a" ], "Listeners" : [ { "LoadBalancerPort" : "80", "InstancePort" : "80", "Protocol" : "HTTP" } ] } }, "myDNS" : { "Type" : "AWS::Route53::RecordSetGroup", "Properties" : { "HostedZoneName" : "example.com.", "Comment" : "Zone apex alias targeted to myELB LoadBalancer.", "RecordSets" : [ { "Name" : "example.com.", "Type" : "A", "AliasTarget" : { "HostedZoneId" : { "Fn::GetAtt" : ["myELB", "CanonicalHostedZoneNameID"] }, "DNSName" : { "Fn::GetAtt" : ["myELB","DNSName"] } } } ] } }

適用於第 1 版負載平衡器的 YAML

myELB: Type: AWS::ElasticLoadBalancing::LoadBalancer Properties: AvailabilityZones: - "us-east-1a" Listeners: - LoadBalancerPort: '80' InstancePort: '80' Protocol: HTTP myDNS: Type: AWS::Route53::RecordSetGroup Properties: HostedZoneName: example.com. Comment: Zone apex alias targeted to myELB LoadBalancer. RecordSets: - Name: example.com. Type: A AliasTarget: HostedZoneId: !GetAtt 'myELB.CanonicalHostedZoneNameID' DNSName: !GetAtt 'myELB.DNSName'

適用於第 2 版負載平衡器的 JSON

"myELB" : { "Type" : "AWS::ElasticLoadBalancing::LoadBalancer", "Properties" : { "Subnets" : [ {"Ref": "SubnetAZ1"}, {"Ref" : "SubnetAZ2"} ] } }, "myDNS" : { "Type" : "AWS::Route53::RecordSetGroup", "Properties" : { "HostedZoneName" : "example.com.", "Comment" : "Zone apex alias targeted to myELB LoadBalancer.", "RecordSets" : [ { "Name" : "example.com.", "Type" : "A", "AliasTarget" : { "HostedZoneId" : { "Fn::GetAtt" : ["myELB", "CanonicalHostedZoneID"] }, "DNSName" : { "Fn::GetAtt" : ["myELB","DNSName"] } } } ] } }

適用於第 2 版負載平衡器的 YAML

myELB: Type: AWS::ElasticLoadBalancingV2::LoadBalancer Properties: Subnets: - Ref: SubnetAZ1 - Ref: SubnetAZ2 myDNS: Type: AWS::Route53::RecordSetGroup Properties: HostedZoneName: example.com. Comment: Zone apex alias targeted to myELB LoadBalancer. RecordSets: - Name: example.com. Type: A AliasTarget: HostedZoneId: !GetAtt 'myELB.CanonicalHostedZoneID' DNSName: !GetAtt 'myELB.DNSName'

CloudFront 分佈的別名資源紀錄集

以下範例建立別名資源紀錄集,以將查詢路由至指定的 CloudFront 分發。

注意

當您建立別名資源紀錄集時,您必須為 Z2FDTNDATAQYW2 屬性指定 HostedZoneId,如以下範例中所示。CloudFront 的別名資源紀錄集無法在私有區域中建立。

JSON

{ "myDNS": { "Type": "AWS::Route53::RecordSetGroup", "Properties": { "HostedZoneId": { "Ref": "myHostedZoneID" }, "RecordSets": [ { "Name": { "Ref": "myRecordSetDomainName" }, "Type": "A", "AliasTarget": { "HostedZoneId": "Z2FDTNDATAQYW2", "DNSName": { "Fn::GetAtt": [ "myCloudFrontDistribution", "DomainName" ] } } } ] } } }

YAML

myDNS: Type: 'AWS::Route53::RecordSetGroup' Properties: HostedZoneId: !Ref myHostedZoneID RecordSets: - Name: !Ref myRecordSetDomainName Type: A AliasTarget: HostedZoneId: Z2FDTNDATAQYW2 DNSName: !GetAtt - myCloudFrontDistribution - DomainName

下一個主題:

Amazon S3

上一個主題:

Amazon RDS
隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。