Guy Grin
Guy Grin

Reputation: 2034

AWS API Gateway generated sdk request errors

I've created an API using AWS API Gateway. All of the methods used in the API require IAM authentication.

I tried to test the API locally and got the following exception:

myapi.model.MyAPIException: The request signature we   calculated does not match the signature you provided. Check your AWS Secret  Access Key and signing method. Consult the service documentation for details.
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1632)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1304)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1058)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:743)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:717)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)
    at com.amazonaws.client.ClientHandlerImpl.doInvoke(ClientHandlerImpl.java:204)
    at com.amazonaws.client.ClientHandlerImpl.invoke(ClientHandlerImpl.java:185)
    at com.amazonaws.client.ClientHandlerImpl.execute(ClientHandlerImpl.java:93)
    at com.amazonaws.opensdk.protect.client.SdkClientHandler.execute(SdkClientHandler.java:42)
    at myapi.MyAPIClient.myMethod(MyAPIClient.java:101)
    ...

For building the request I used the following code:

public static void main(String[] args) {

    MyAPI client = MyAPI .builder()
                .apiKey(myApiKey)
                .iamCredentials(DefaultAWSCredentialsProviderChain.getInstance())
                .build();

    MyMethodRequest myMethodRequest = new MyMethodRequest().arg(methodArg);

    MyMethodResult result = client.myMethod(myMethodRequest);
}

The credentials loaded by the DefaultAWSCredentialsProviderChain are my credentials which have admin access to all of my AWS services so I'm not sure what is wrong.

Any help is appreciated.

Upvotes: 0

Views: 290

Answers (2)

Guy Grin
Guy Grin

Reputation: 2034

The problem ended being having entered the wrong apiKey for the API. When I changed it to a valid API key generated by API Gateway everything worked.

Also, you have to make sure the API Key is linked to a valid usage plan or it will not work

Upvotes: 1

Tryliom
Tryliom

Reputation: 109

Usually class more like:

package ...;

public class ListingMusic implements 
RequestHandler<HashMap<String, Object>, String> {

    @Override
    public String handleRequest(HashMap<String, Object> input, Context context) {
        ...
    }

}

Maybe it can be that your lambda can't start

Upvotes: 0

Related Questions