Reto Höhener
Reto Höhener

Reputation: 5808

AWS SDK Route53: trying to create A record, but getting generic InvalidInputException: Invalid request

Can someone help me with this generic exception? Any ideas? Up to this point AWS messages were very helpful, but now I am stuck.

com.amazonaws.services.route53.model.InvalidInputException: Invalid request (Service: AmazonRoute53; Status Code: 400; Error Code: InvalidInput; Request ID: UUID)

I already fixed permission problems. The javadoc of withTTL says "If you're creating or updating an alias resource record set, omit TTL. Amazon Route 53 uses the value of TTL for the alias target.", but the alias target does not offer such a method.

 AmazonRoute53 route53 = AmazonRoute53ClientBuilder.standard() //
    .withRegion(Regions.EU_CENTRAL_1) // I thought Route53 is region-independent?
    .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY)))
    .build();

AliasTarget aliasTarget = new AliasTarget() //
    .withHostedZoneId(HOSTED_ZONE_ID) //
    .withEvaluateTargetHealth(false) //
    .withDNSName("1.2.3.4"); // using a valid IP here

ResourceRecordSet recordSet = new ResourceRecordSet() //
    .withType(RRType.A) //
    .withName("sub.domain.com") // using my own domain here
    .withTTL(300L) //
    .withAliasTarget(aliasTarget);

Change change = new Change() //
    .withAction(ChangeAction.UPSERT) //
    .withResourceRecordSet(recordSet);

route53.changeResourceRecordSets(new ChangeResourceRecordSetsRequest() //
    .withHostedZoneId(HOSTED_ZONE_ID) //
    .withChangeBatch(new ChangeBatch().withChanges(change)));

Upvotes: 0

Views: 1152

Answers (1)

Reto Höhener
Reto Höhener

Reputation: 5808

Ok I finally figured it out. I was doing it all wrong, no alias target needed (API lured me down that alley).

AmazonRoute53 route53 = AmazonRoute53ClientBuilder.standard() //
    .withRegion(REGION) //
    .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY)))
    .build();

ResourceRecordSet recordSet = new ResourceRecordSet() //
    .withType(RRType.A) //
    .withName("sub.domain.com") //
    .withTTL(300L) //
    .withResourceRecords(new ResourceRecord().withValue("1.2.3.4"));

Change change = new Change() //
    .withAction(ChangeAction.UPSERT) //
    .withResourceRecordSet(recordSet);

route53.changeResourceRecordSets(new ChangeResourceRecordSetsRequest() //
    .withHostedZoneId(HOSTED_ZONE_ID) //
    .withChangeBatch(new ChangeBatch().withChanges(change)));

Upvotes: 2

Related Questions