Search code examples
javaamazon-web-servicesaws-lambda

how to use a proxy above an aws lambda invocation


I want to invoke an aws lambda function through java code using the aws lamdba sdk while specifying a proxy above the client. How can I achieve such scenario? I did not manage to locate any documentation on aws docs.

I am using

<dependency>
    <groupId>software.amazon.awssdk</groupId>
    <artifactId>lambda</artifactId>
    <version>2.21.10</version>
</dependency>

I have something like this, and i want to specify a proxy here. Any idea?

@PostConstruct
public void init() {
    lambdaClient = LambdaClient.builder()
            // specify a proxy here maybe or a custom httpclient ?
            .region(Region.EU_SOUTH_1)
            .build();
}

Solution

  • You can easily build your own custom http client for the AWS SDK:

    @PostConstruct
    public void init() {
      final SdkHttpClient httpClient = ApacheHttpClient.builder()
                .proxyConfiguration(ProxyConfiguration.builder()
                .useSystemPropertyValues(true)
                .build())
           .build();
    
      lambdaClient = LambdaClient.builder().httpClient(httpClient).build();
    }