How to use the AWS API Gateway Java SDK to access a Webservice

5.3k Views Asked by At

I have the following endpoint that a client sent me:

https://{restapi_id}.execute-api.{region}.amazonaws.com/test/v1/items?type=ABC

Since this request needs to be called with the AWS Authorization process I wanted to use the API Gateway SDK, but I can't find a straightforward example on how to call it. I was able to successfully test the API call using Postman (as exaplained in the AWS docs), but I don't know how to specify it using the SDK. The ENDPOINT should be the full URL? How should I make a call beyond this code? I tried using the GetResourceRequest, but that doesn't seem right. If so, what part of this URL I have is the resource?

This is code where I'm stuck with:

BasicAWSCredentials awsCreds = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);

AmazonApiGatewayClient api = new AmazonApiGatewayClient(awsCreds);
api.setRegion(Region.getRegion(Regions.US_EAST_1));
api.setServiceNameIntern("execute-api");
api.setEndpoint(ENDPOINT);
2

There are 2 best solutions below

0
On

AmazonApiGatewayClient is for managing the apis, you cannot use it to call your api.

We just launched support to generate a Java SDK for an apis, you can use that to call your api (link to docs). Note that you need to generate the SDK from the export tab in the stage.

0
On

Here's an open-source generic SDK you can use to do this: https://github.com/rpgreen/apigateway-generic-java-sdk

You can also generate your own SDK as per https://aws.amazon.com/blogs/developer/api-gateway-java-sdk/