Skip to content

Instantly share code, notes, and snippets.

@yyuu
Created April 20, 2012 08:59
Show Gist options
  • Select an option

  • Save yyuu/2427218 to your computer and use it in GitHub Desktop.

Select an option

Save yyuu/2427218 to your computer and use it in GitHub Desktop.
create route53 resource record with clojure and aws-sdk-java
(ns route53-create-record.core)
(import '(com.amazonaws.auth BasicAWSCredentials)
'(com.amazonaws.services.route53 AmazonRoute53Client)
'(com.amazonaws.services.route53.model GetHostedZoneRequest
ChangeResourceRecordSetsRequest
ChangeBatch
Change
ListResourceRecordSetsRequest
ResourceRecordSet
ResourceRecord))
(defn -main [& args]
(def aws_access_key_id (System/getenv "AWS_ACCESS_KEY_ID"))
(def aws_secret_access_key (System/getenv "AWS_SECRET_ACCESS_KEY"))
(def route53 (new AmazonRoute53Client
(new BasicAWSCredentials aws_access_key_id aws_secret_access_key)))
(let [zone (.getHostedZone (.getHostedZone route53 (new GetHostedZoneRequest "PUT_ZONE_ID_HERE")))]
(let [req (new ChangeResourceRecordSetsRequest (.getId zone)
(new ChangeBatch
(list (new Change "CREATE"
(doto (new ResourceRecordSet "foo.example.com", "A")
(.setTTL 300)
(.setSetIdentifier "node1")
(.setWeight 10)
(.setResourceRecords (list (new ResourceRecord "127.0.0.10")))
))
)))]
(.changeResourceRecordSets route53 req))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment