3

I am working on a script that creates a website bucket and then assigns dns entries to it.

I have no idea how to assign the proper ALIAS record to the apex so that it points to the bucket.

This function is takes in an r53 connection, the zone object, and a dict with the bucket objects. It tries to add the proper records to the zone.

How would I go about correctly creating dns entries that would forward to the buckets?

Note that the www bucket forwards to the apex.

def create_website_records(r53,zone,buckets):
  records = r53.get_all_rrsets(zone.id)
  change = records.add_change('CREATE', zone.name, 'A',alias_hosted_zone_id=buckets['apex'])
  change.add_value('%s' % buckets['apex'].get_website_endpoint())
  change = records.add_change('CREATE', 'www.' + zone.name, 'CNAME')
  change.add_value('%s' % buckets['www'].get_website_endpoint())
  records.commit()
  return records

1 Answer 1

1

Apparently you cant get the bucket's hosted_zone_id via the api

https://forums.aws.amazon.com/thread.jspa?threadID=116724#

You have to manually set the hosted zone (you can look them up here).

My method ended up looking like this:

def create_website_records(r53,zone,buckets):
  records = r53.get_all_rrsets(zone.id)
  change = records.add_change('CREATE', zone.name,    'A',alias_hosted_zone_id='Z3AQBSTGFYJSTF',alias_dns_name='s3-website-us-east-1.amazonaws.com')
  change.add_value('ALIAS s3-website-us-east-1.amazonaws.com (Z3AQBSTGFYJSTF)')
  change = records.add_change('CREATE', 'www.' + zone.name, 'CNAME')
  change.add_value('%s' % buckets['www'].get_website_endpoint())
  records.commit()
  return records

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.