AWS SQS Java SDK: Endpoint Override With A Path

3.3k views Asked by At

I am using the AWS SDK version 2.14.26.

I want to be able to point it to my simulator for AWS SQS, which allows for me to do fancy things such as return errors, delay responses, ect. I do have ElasticMQ, but I also want to do the fancy things, for which I have a webapp which simulates many things, one of which would be SQS.

My webapp is hosted at http://localhost:8088/simulators/v1/aws/sqs. I would hope I could then expect the sdk to make any API requests starting from that path https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-making-api-requests.html

For example,

https://sqs.eu-west-2.amazonaws.com/   
?Action=CreateQueue
&DefaultVisibilityTimeout=40
&QueueName=MyQueue
&Version=2012-11-05
&AUTHPARAMS

Would become

http://localhost:8088/simulators/v1/aws/sqs   
?Action=CreateQueue
&DefaultVisibilityTimeout=40
&QueueName=MyQueue
&Version=2012-11-05
&AUTHPARAMS

But when I create the client and try to get a queue:

SqsClient client = SqsClient.builder()
                .region(Region.of("SIMULATOR"))
                .credentialsProvider((()->AwsBasicCredentials.create("ignored", "bySim")))
                .endpointOverride(new URI("http://localhost:8088/simulators/v1/aws/sqs"))
                .build();
client.getQueueUrl(GetQueueUrlRequest.builder()
      .queueName("test123")
      .build());

I get

software.amazon.awssdk.services.sqs.model.SqsException: null (Service: Sqs, Status Code: 404, Request ID: null, Extended Request ID: null)

Looking at wireshark, it seems to just be pointing at / rather than the endpoint I wanted, which caused it to get a 404

1287    2020-10-12 16:07:10.982955272   127.0.0.1   127.0.0.1   HTTP    801 POST / HTTP/1.1  (application/x-www-form-urlencoded)
[Full request URI: http://localhost:8088/]

Is there a way to get the aws sdk to start from the path of /simulators/v1/aws/sqs? Because I would like my simulator app to be able to simulate may APIs, and not have to use the root path.

0

There are 0 answers