Trying to make a "Hello World" AWS API Gateway GET API call from Android using Generated SDK

Viewed 2855

I'm trying to get the AWS API gateway generated SDK to work, I've created an API gateway GET API which works fine when I hit the url from a browser/httpclient, but not with Android.

With Android, I'm trying to use the Android SDK that is generated by AWS API Gateway. The documented example I found is very unclear to me, it uses types and methods which do not exist in the AWS SDK:

http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-generate-sdk-android.html

For example:

//     If the API exposes a 'GET /{a}/{b}/{op}'  method, you can call the following SDK method to invoke the request,

Result.output = client.aBOpGet(a, b, c)

I do not know what aBOpGET is suppose to be, nor do I know what Result is.

while I was able to follow along to build/import the jars, I couldn't follow their code example. So, I came up with this based on browsing the SDK code:

import android.os.AsyncTask;
import android.util.Log;

import com.amazonaws.mobileconnectors.apigateway.ApiClientFactory;
import com.amazonaws.mobileconnectors.apigateway.ApiRequest;
import com.amazonaws.mobileconnectors.apigateway.ApiResponse;

import Client.LambdaMicroserviceClient;


public class APIGatewayHandler extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(Void... params) {
        //gateway
        ApiClientFactory factory = new ApiClientFactory();
        final LambdaMicroserviceClient client = factory.build(LambdaMicroserviceClient.class);

        ApiRequest request = new ApiRequest("/QueryNetSumMinute");


        ApiResponse apiResponse = client.execute(request);
        int responseCode = apiResponse.getStatusCode();

        android.util.Log.v("Request: ", request.toString());
        android.util.Log.v("response Code: ", String.valueOf(responseCode));
        android.util.Log.v("response Status Text: ",    apiResponse.getStatusText());
        //android.util.Log.v("responseCode: ", String.valueOf(responseCode));
        return null;
    }

    @Override
    public void onPostExecute(Void var) {
        Log.d("onPostExecute", "complete");
    }
}

That runs fine, but on the client response I get a 403 Forbidden error when invoked.

I have info logging enabled on API gateway and I can see detailed information from an http request sent by a browser, but I see nothing from this Android code.

What I suspect is happening, is that the client is hitting the BASE URL of the API without specifying the method "/QueryNetSumMinute" which from testing from a browser does indeed return 403

1 Answers
Related