'Unable to connect to Amazon SQS using amazon sdk

Iam trying to send a message to SQS queue based on This Code. Since my code needs a token access key and Token, My authentication mechanism is also different. So my code looks something like this

public AmazonSQS sqsClient(String accessKey,String accessSecret, String token){
BasicSessionCredentials sessionCredentials = new BasicSessionCredentials(accessKey,accessSecret,token);
AmazonSQS client = AmazonSQSClientBuilder.standard()
                   .withCredentials(new AWSStaticCredentailsProvider(sessionCredentials))
                   .withRegion(Regions.US_EAST_1)
                   .withClientConfiguration(PredefinedClientConfigurations.defaultConfig().withProxyHost("<myhost>"))
                   .build();
return client;
}

I found that i was not able to send message with client as it keeps giving me connection timeout to sqs.us-east-1.amazonawsclient.com

Ps: The proxy seems to be right because Iam able to send the message through aws cli with the same proxy, same set of tokens.



Solution 1:[1]

Try this: Set the value for ACCESS_KEY, SECRET_KEY, AWS_REGION according to your iamrole.

    public AmazonSQSAsync amazonSQSAsync() {

        AmazonSQSAsync amazonSQSAsync = null;

        AmazonSQSAsyncClientBuilder amazonSQSAsyncClientBuilder = AmazonSQSAsyncClientBuilder.standard();
        amazonSQSAsyncClientBuilder.withRegion(AWS_REGION);

        BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);

        amazonSQSAsyncClientBuilder.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials));

        amazonSQSAsync = amazonSQSAsyncClientBuilder.build();

        return amazonSQSAsync;

    }

Please read these article to get learn about amazon sqs queues and to implement :

  1. https://hydroid.medium.com/aws-sqs-simple-queue-service-14699b8cca7f
  2. https://hydroid.medium.com/create-get-amazon-sqs-queues-8d9c5381f3e2

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anushil Kumar