This is a simple generic Java client for Amazon API Gateway endpoints. It is useful when you don't necessarily want to generate a strongly-typed SDK, such as when prototyping or scripting.

It is optimized to run from a Lambda function and does not require extra dependencies beyond the AWS SDK, which is already bundled in the Lambda runtime.

It does not make any assumptions about the wire format of your requests and responses. You are free to parse response bodies as you see fit, and the raw HTTP response data is included in the wrapped response.





From source

git clone https://github.com/rpgreen/apigateway-generic-java-sdk.git

# Optional:
cd apigateway-generic-java-sdk
mvn install


GenericApiGatewayClient client = new GenericApiGatewayClientBuilder()
        .withClientConfiguration(new ClientConfiguration())
        .withCredentials(new EnvironmentVariableCredentialsProvider())

Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");

try {
    GenericApiGatewayResponse response = client.execute(
            new GenericApiGatewayRequestBuilder()
                    .withBody(new ByteArrayInputStream("foo".getBytes()))

    System.out.println("Response: " + response.getBody());
    System.out.println("Status: " + response.getHttpResponse().getStatusCode());

} catch (GenericApiGatewayException e) {   // exception thrown for any non-2xx response
    System.out.println(String.format("Client threw exception with message %s and status code %s", 
            e.getMessage(), e.getStatusCode()));