Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
469 views
in Technique[技术] by (71.8m points)

amazon web services - List resource record sets from hosted zone in route53 giving a very weird error

My purpose is to list all records available in all hosted zones. I created a listResourceRecordSetsRequest builder object and pass it through the response method to retrieve all the resource records but for some reason I get an error.

My code which is wrong and causing the error:

The line which starts with def response = .... is what's giving an error

ArrayList<ResourceRecordSet> getResourceRecords(HostedZone hostedZone){

        def request = ListResourceRecordSetsRequest.builder().hostedZoneId(hostedZone.id()).maxItems("1000").build()
        def response = route53Client.listResourceRecordSets(request as Consumer<ListResourceRecordSetsRequest.Builder>)
        return response.resourceRecordSets()
    }

Error:

groovy.lang.MissingMethodException: No signature of method: software.amazon.awssdk.services.route53.model.ListResourceRecordSetsRequest.accept() is applicable for argument types: (software.amazon.awssdk.services.route53.model.ListResourceRecordSetsRequest$BuilderImpl) values: [software.amazon.awssdk.services.route53.model.ListResourceRecordSetsRequest$BuilderImpl@56eafaa0]

I appreciate the help in advance!

question from:https://stackoverflow.com/questions/65837245/list-resource-record-sets-from-hosted-zone-in-route53-giving-a-very-weird-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

What AWS SDK are you using - V2? I just tested this in AWS Java V2 API and it works fine.

enter image description here

Full Java V2 example.

import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.route53.Route53Client;
import software.amazon.awssdk.services.route53.model.*;

import java.util.List;

public class ListResourceRecordSets {

    public static void main(String[] args) {

        Region region = Region.AWS_GLOBAL;
        Route53Client route53Client = Route53Client.builder()
                .region(region)
                .build();

        listResourceRecord(route53Client);
        route53Client.close();
    }

    public static void listResourceRecord(Route53Client route53Client) {

        try {

            ListResourceRecordSetsRequest request = ListResourceRecordSetsRequest.builder()
                    .hostedZoneId("XXXXX5442QZ69T8EEX5SZ")
                    .maxItems("12")
                    .build();

            ListResourceRecordSetsResponse listResourceRecordSets = route53Client.listResourceRecordSets(request);
            List<ResourceRecordSet> records = listResourceRecordSets.resourceRecordSets();

            for (ResourceRecordSet record : records) {
                System.out.println("The Record name is: " + record.name());

            }

        } catch (Route53Exception e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...