Skip to content

Instantly share code, notes, and snippets.

@mindcrime
Created March 30, 2016 00:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindcrime/b697acc97e68b721669353aa8c6b19b2 to your computer and use it in GitHub Desktop.
Save mindcrime/b697acc97e68b721669353aa8c6b19b2 to your computer and use it in GitHub Desktop.
How to add a subdomain with AWS Route 53 using the Java SDK
AWSCredentials credentials = null;
try
{
credentials = new PropertiesFileCredentialsProvider( "credentials.properties" ).getCredentials();
}
catch (Exception e)
{
throw new AmazonClientException(
"Cannot load the credentials from the credential profiles file. " +
"Please make sure that your credentials file is at the correct " +
"location (~/.aws/credentials), and is in valid format.",
e);
}
AmazonRoute53Client route53Client = new AmazonRoute53Client( credentials );
ChangeResourceRecordSetsRequest changeResourceRecordSetsRequest = new ChangeResourceRecordSetsRequest();
changeResourceRecordSetsRequest.setHostedZoneId( "Z2XRDW73429RSKL" ); // use your zone ID, OK?
ChangeBatch changeBatch = new ChangeBatch();
List<Change> changes = new ArrayList<Change>();
Change aChange = new Change();
aChange.setAction( ChangeAction.CREATE );
ResourceRecordSet resourceRecordSet = new ResourceRecordSet();
resourceRecordSet.setName( "test1.example.com" ); // use your own domain, OK?
resourceRecordSet.setTTL( 300L );
resourceRecordSet.setType( "A" );
List<ResourceRecord> resourceRecords = new ArrayList<ResourceRecord>();
ResourceRecord aRecord = new ResourceRecord();
aRecord.setValue( "666.777.888.999" ); // use a real IP address, OK?
resourceRecords.add( aRecord );
resourceRecordSet.setResourceRecords( resourceRecords );
aChange.setResourceRecordSet( resourceRecordSet );
changes.add( aChange );
changeBatch.setChanges( changes );
changeBatch.setComment( "Just a test change..." );
changeResourceRecordSetsRequest.setChangeBatch( changeBatch );
route53Client.changeResourceRecordSets( changeResourceRecordSetsRequest );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment