I have LocalStack in my local machine for resolving AWS service dependencies. I am trying to test my application which connects to the LocalStack SQS. I have deployed my application as a docker container. The problem is when I am accessing SQS getQueueUrl from my application container, it is giving me localhost as AWS endpoint. But I mentioned my local machine’s private IP while setting up Java SQS client.
"exception":"com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to localhost:4566 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1207) ~[aws-java-sdk-core-1.11.822.jar:?]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1153) ~[aws-java-sdk-core-1.11.822.jar:?]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:802) ~[aws-java-sdk-core-1.11.822.jar:?]
The problem is that LocalStack does not override hostname property. So while initializing LocalStack, we need to define HOSTNAME_EXTERNAL field in docker-compose.yml file of LocalStack. It would be somewhat similar to below:
- HOSTNAME_EXTERNAL: <hostname/ip of devbox>
Once you define proper hostname or IP address in HOSTNAME_EXTERNAL field and start LocalStack , that should solve the problem.