John Mercier
John Mercier

Reputation: 1705

How to build AmazonSQS with proxy settings

I need to create an AmazonSQS that goes through a specific proxy (not using jvm defaults). I want to use all of the standard defaults and only change the proxy. Is there any easy way to set the proxy information? So far this is what I have.

AmazonSQSClientBuilder builder = AmazonSQSClientBuilder.standard();
AmazonSQS sqsClient = builder.withClientConfiguration(
    builder.getClientConfiguration()
    .withProxyHost("hostname")
    .withProxyPort(port)
    .withNonProxyHosts("no proxy hosts"))
    .build()

This results in a NPE on builder.getClientConfiguration().withProxyHost("hostname"). How do I set client configuration in the builder to a configuration with defaults and then setup the proxy info?

Upvotes: 2

Views: 2808

Answers (1)

John Mercier
John Mercier

Reputation: 1705

builder did not have a configuration set. Using PredefinedClientConfigurations fixed this.

AmazonSQSClientBuilder builder = AmazonSQSClientBuilder.standard();
AmazonSQS sqsClient = builder.withClientConfiguration(
    PredefinedClientConfigurations.defaultConfig()
    .withProxyHost("hostname")
    .withProxyPort(port)
    .withNonProxyHosts("no proxy hosts"))
    .build()

This will create an AmazonSQS with all of the defaults and a proxy host setup.

Upvotes: 3

Related Questions