Question

I'm trying to programmatically create a Route 53 CNAME record using the ALIAS settings with the ruby aws-sdk gem.

I can't find a way of doing this in the documentation. I see how to create a record itself but not how I would create an ALIAS one.

rrsets = AWS::Route53::HostedZone.new(hosted_zone_id).rrsets
rrset = rrsets.create('foo.example.com.', 'CNAME', :ttl => 300, :resource_records => [{:value => 'foo.example.com.s3.amazon.weast.uk'}])
Was it helpful?

Solution

Below is an example of how you would alias to a S3 Web Site Endpoint in US-WEST-2.

$irb

irb> require 'aws-sdk'
irb> rrsets = AWS::Route53::HostedZone.new('Z1234').rrsets #replace Z123 with your hosted zone in which you are creating the record.
irb> rrset = rrsets.create('foo.example.com.', 'A', :alias_target => {:hosted_zone_id => 'Z3BJ6K6RIION7M', :dns_name => 's3-website-us-west-2.amazonaws.com' , :evaluate_target_health => false }) # Z3BJ6K6RIION7M is the target hosted zone, in this case Z3BJ6K6RIION7M and can be obtained from the below link, if it's s3.

Endpoints & Hosted Zone Ids: http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

Note: Alias records can not have TTLs and require target hosted zone ids. The reason they don't have TTLs is that they use the target's TTL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top