Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from CNAME to Alias Route53 records #1074

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,7 @@ def test_get_domain_respects_route53_setting(self, client, template):
"HostedZones": [{"Id": "somezone"}],
}
zappa_core.route53.list_resource_record_sets.return_value = {
"ResourceRecordSets": [{"Type": "CNAME", "Name": "test_domain1"}]
"ResourceRecordSets": [{"Type": "A", "Name": "test_domain1"}]
}

record = zappa_core.get_domain_name("test_domain")
Expand Down
34 changes: 9 additions & 25 deletions zappa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2655,36 +2655,20 @@ def update_route53_records(self, domain_name, dns_name):
"""
zone_id = self.get_hosted_zone_id_for_domain(domain_name)

is_apex = (
self.route53.get_hosted_zone(Id=zone_id)["HostedZone"]["Name"][:-1]
== domain_name
)
if is_apex:
record_set = {
"Name": domain_name,
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z2FDTNDATAQYW2", # This is a magic value that means "CloudFront"
"DNSName": dns_name,
"EvaluateTargetHealth": False,
},
}
else:
record_set = {
"Name": domain_name,
"Type": "CNAME",
"ResourceRecords": [{"Value": dns_name}],
"TTL": 60,
}
record_set = {
"Name": domain_name,
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z2FDTNDATAQYW2", # This is a magic value that means "CloudFront"
"DNSName": dns_name,
"EvaluateTargetHealth": False,
},
}

# Related: https://github.com/boto/boto3/issues/157
# and: http://docs.aws.amazon.com/Route53/latest/APIReference/CreateAliasRRSAPI.html
# and policy: https://spin.atomicobject.com/2016/04/28/route-53-hosted-zone-managment/
# pure_zone_id = zone_id.split('/hostedzone/')[1]

# XXX: ClientError: An error occurred (InvalidChangeBatch) when calling the ChangeResourceRecordSets operation:
# Tried to create an alias that targets d1awfeji80d0k2.cloudfront.net., type A in zone Z1XWOQP59BYF6Z,
# but the alias target name does not lie within the target zone
response = self.route53.change_resource_record_sets(
HostedZoneId=zone_id,
ChangeBatch={
Expand Down