Skip to content

Instantly share code, notes, and snippets.

@ns408
Forked from kixorz/aws_iam_policy.json
Created June 18, 2014 14:57
Show Gist options
  • Save ns408/56453360d0d4b59d4480 to your computer and use it in GitHub Desktop.
Save ns408/56453360d0d4b59d4480 to your computer and use it in GitHub Desktop.
{
"Statement": [
{
"Action": [
"route53:ChangeResourceRecordSets",
"route53:GetHostedZone",
"route53:ListResourceRecordSets"
],
"Effect": "Allow",
"Resource": [
"arn:aws:route53:::hostedzone/<your hosted zone id>"
]
}
]
}
#!/usr/bin/env ruby
require 'aws-sdk'
require 'net/http'
AWS.config({
:access_key_id => '<iam user key>',
:secret_access_key => '<iam user secret>'
})
hostname = ARGV[0].to_s
domain = '<your domain name>'
zone = '<your hosted zone id>'
ttl = 60
metadata_endpoint = 'http://169.254.169.254/latest/meta-data/'
hostname_local = Net::HTTP.get( URI.parse( metadata_endpoint + 'local-hostname' ) )
hostname_public = Net::HTTP.get( URI.parse( metadata_endpoint + 'public-hostname' ) )
records = [{
:alias => [ hostname, domain, '' ] * '.',
:target => hostname_local
},{
:alias => [ hostname + '-public', domain, '' ] * '.',
:target => hostname_public
}]
#update DNS records
rrsets = AWS::Route53::HostedZone.new(zone).rrsets
records.each{ |record|
rrset = rrsets[
record[ :alias ],
'CNAME'
]
if rrset.exists?
rrset.delete
end
rrset = rrsets.create(
record[ :alias ],
'CNAME',
:ttl => ttl,
:resource_records => [
{ :value => record[ :target ] }
]
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment