Reputation: 1399
I'm using AWS Lambda w/ API gateway triggers and I am running into an issue.
I'm using RetroFit to make a POST request and I'm getting a 403 for my response back. I am passing a JSON with a URL where the amazon service will do something with it. Is there something I need to put in the headers? I removed authorization from the request.
Here is the raw message and it doesn't give me a detailed message.
"Response{protocol=h2, code=403, message=, url=https://eun533ayha.execute-api.us-west-1.amazonaws.com/lio}"
Interface/Retrofit service
public interface AmazonService {
@Headers("Content-Type: application/json; charset=utf8")
@POST("/lio")
Observable<ResponseBody> getAmazonResponse(@Body JSONObject input);
}
amazonRetrofit = new Retrofit.Builder()
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.callbackExecutor(executor)
.client(okHttpClient)
.baseUrl("https://eun533ayha.execute-api.us-west-1.amazonaws.com/Prod/")
.build();
AmazonService as = amazonRetrofit.create(AmazonService.class);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("url", "www.google.com");
} catch (JSONException e) {
e.printStackTrace();
}
Observable<ResponseBody> obs = as.getAmazonResponse(jsonObject);
obs.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<ResponseBody>() {
@Override
public void onCompleted() {
Log.d(TAG, "response onCompleted()");
}
@Override
public void onError(Throwable throwable) {
Log.d(TAG, "response onError()");
}
@Override
public void onNext(ResponseBody response) {
Log.d(TAG, "response onNext()");
}
});
Upvotes: 0
Views: 1236
Reputation: 6510
I think you are using Retrofit 2, and Retrofit 2 uses the same rules as .
If you have a leading '/' on your path, it will consider as absolute path.
public interface AmazonService {
@Headers("Content-Type: application/json; charset=utf8")
@POST("/lio")
Observable<ResponseBody> getAmazonResponse();
}
amazonRetrofit = new Retrofit.Builder()
.client(okHttpClient)
.baseUrl("https://eun533ayha.execute-api.us-west-1.amazonaws.com/Prod/")
.build();
Result: https://eun533ayha.execute-api.us-west-1.amazonaws.com/lio
If you remove the leading '/' on your path, it will consider as related path.
public interface AmazonService {
@Headers("Content-Type: application/json; charset=utf8")
@POST("lio")
Observable<ResponseBody> getAmazonResponse();
}
amazonRetrofit = new Retrofit.Builder()
.client(okHttpClient)
.baseUrl("https://eun533ayha.execute-api.us-west-1.amazonaws.com/Prod/")
.build();
Result: https://eun533ayha.execute-api.us-west-1.amazonaws.com/Prod/lio
In your case, it looks like that you have a stage 'Prod' and your integration is on the resource '/lio'. I think it will work if you remove the leading '/'.
Upvotes: 2