diff --git a/moto/route53/models.py b/moto/route53/models.py
index 3760d3817..071dcfac7 100644
--- a/moto/route53/models.py
+++ b/moto/route53/models.py
@@ -85,6 +85,7 @@ class RecordSet(BaseModel):
self.health_check = kwargs.get('HealthCheckId')
self.hosted_zone_name = kwargs.get('HostedZoneName')
self.hosted_zone_id = kwargs.get('HostedZoneId')
+ self.alias_target = kwargs.get('AliasTarget')
@classmethod
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
@@ -143,6 +144,13 @@ class RecordSet(BaseModel):
{% if record_set.ttl %}
{{ record_set.ttl }}
{% endif %}
+ {% if record_set.alias_target %}
+
+ {{ record_set.alias_target['HostedZoneId'] }}
+ {{ record_set.alias_target['DNSName'] }}
+ {{ record_set.alias_target['EvaluateTargetHealth'] }}
+
+ {% else %}
{% for record in record_set.records %}
@@ -150,6 +158,7 @@ class RecordSet(BaseModel):
{% endfor %}
+ {% endif %}
{% if record_set.health_check %}
{{ record_set.health_check }}
{% endif %}
diff --git a/moto/route53/responses.py b/moto/route53/responses.py
index 98ffa4c47..981362b12 100644
--- a/moto/route53/responses.py
+++ b/moto/route53/responses.py
@@ -134,10 +134,7 @@ class Route53(BaseResponse):
# Depending on how many records there are, this may
# or may not be a list
resource_records = [resource_records]
- record_values = [x['Value'] for x in resource_records]
- elif 'AliasTarget' in record_set:
- record_values = [record_set['AliasTarget']['DNSName']]
- record_set['ResourceRecords'] = record_values
+ record_set['ResourceRecords'] = [x['Value'] for x in resource_records]
if action == 'CREATE':
the_zone.add_rrset(record_set)
else:
diff --git a/tests/test_route53/test_route53.py b/tests/test_route53/test_route53.py
index d730f8dcf..97cd82d26 100644
--- a/tests/test_route53/test_route53.py
+++ b/tests/test_route53/test_route53.py
@@ -172,14 +172,16 @@ def test_alias_rrset():
changes.commit()
rrsets = conn.get_all_rrsets(zoneid, type="A")
- rrset_records = [(rr_set.name, rr) for rr_set in rrsets for rr in rr_set.resource_records]
- rrset_records.should.have.length_of(2)
- rrset_records.should.contain(('foo.alias.testdns.aws.com.', 'foo.testdns.aws.com'))
- rrset_records.should.contain(('bar.alias.testdns.aws.com.', 'bar.testdns.aws.com'))
- rrsets[0].resource_records[0].should.equal('foo.testdns.aws.com')
+ alias_targets = [rr_set.alias_dns_name for rr_set in rrsets]
+ alias_targets.should.have.length_of(2)
+ alias_targets.should.contain('foo.testdns.aws.com')
+ alias_targets.should.contain('bar.testdns.aws.com')
+ rrsets[0].alias_dns_name.should.equal('foo.testdns.aws.com')
+ rrsets[0].resource_records.should.have.length_of(0)
rrsets = conn.get_all_rrsets(zoneid, type="CNAME")
rrsets.should.have.length_of(1)
- rrsets[0].resource_records[0].should.equal('bar.testdns.aws.com')
+ rrsets[0].alias_dns_name.should.equal('bar.testdns.aws.com')
+ rrsets[0].resource_records.should.have.length_of(0)
@mock_route53_deprecated
@@ -582,6 +584,39 @@ def test_change_resource_record_sets_crud_valid():
cname_record_detail['TTL'].should.equal(60)
cname_record_detail['ResourceRecords'].should.equal([{'Value': '192.168.1.1'}])
+ # Update to add Alias.
+ cname_alias_record_endpoint_payload = {
+ 'Comment': 'Update to Alias prod.redis.db',
+ 'Changes': [
+ {
+ 'Action': 'UPSERT',
+ 'ResourceRecordSet': {
+ 'Name': 'prod.redis.db.',
+ 'Type': 'A',
+ 'TTL': 60,
+ 'AliasTarget': {
+ 'HostedZoneId': hosted_zone_id,
+ 'DNSName': 'prod.redis.alias.',
+ 'EvaluateTargetHealth': False,
+ }
+ }
+ }
+ ]
+ }
+ conn.change_resource_record_sets(HostedZoneId=hosted_zone_id, ChangeBatch=cname_alias_record_endpoint_payload)
+
+ response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
+ cname_alias_record_detail = response['ResourceRecordSets'][0]
+ cname_alias_record_detail['Name'].should.equal('prod.redis.db.')
+ cname_alias_record_detail['Type'].should.equal('A')
+ cname_alias_record_detail['TTL'].should.equal(60)
+ cname_alias_record_detail['AliasTarget'].should.equal({
+ 'HostedZoneId': hosted_zone_id,
+ 'DNSName': 'prod.redis.alias.',
+ 'EvaluateTargetHealth': False,
+ })
+ cname_alias_record_detail.should_not.contain('ResourceRecords')
+
# Delete record.
delete_payload = {
'Comment': 'delete prod.redis.db',