1
votes

I am new in API gateways. I have python based API deployed on an EC2 server. I can access this as URL http://xxx.xxxxxxx.com/RPC2/. I can see objects, methods in this URL. I am trying to use API gateway for same.

  1. Created API. (ExampleAPI)
  2. Created POST method. (given path http://xxx.xxxxxxx.com/RPC2/ as end point URL ). I have not created the resource since I am expecting HTTP Proxy for all Methods of the resource. Its looks fine when I put my content in the request body. I get a response.
  3. Now I have deployed it to one stage dev1. Got a new endpoint URL.
  4. Also created an API key and attached it with dev1. Also Set API key required true in POST Method Request.

Questions. 1. When I hit dev1 URL (https://xxxxxxxxxxx-api.us-east-1.amazonaws.com/dev1), it does not give me same page as http://xxx.xxxxxxx.com/RPC2/. It gives me {"message":"Missing Authentication Token"} error. Am I missing some fundamentals here?

  1. http://xxx.xxxxxxx.com/RPC2/ do have several methods, so how can I use it? All of them are POST methods. Can I set some parameters or some request body, or some templates? How can I improve this process?

  2. How can I use API key here? Or it won`t work in POST method?

  3. If i do curl -H "Content-Type: application/JSON" -X POST -d "{\"method\": \"app.menu\",\"params\":[] }" https://xxxxxxxxxxx-api.us-east-1.amazonaws.com/dev1 i get same response as i curl http://xxx.xxxxxxx.com/RPC2/. is it the only way to access my dev1 URL or I can create individual methods or string parameters.

Regards, Ashish

1
I replied on the forum post, please check that out forums.aws.amazon.com/thread.jspa?messageID=734000&#734000jackko

1 Answers

1
votes

See answers posted to this forum:

  1. When i hit dev1 URL (https://xxxxxxxxxxx-api.us-east-1.amazonaws.com/dev1), it do not give me same page as http://xxx.xxxxxxx.com/RPC2/. It gives me {"message":"Missing Authentication Token"} error. Am i missing some fundamentals here ?

If you are hitting the URL in a browser with a GET method, it will not work. You have to specify all of the HTTP methods on a resource that you want the client to access. If you hit a method that is not defined, you get that message.

  1. http://xxx.xxxxxxx.com/RPC2/ do have several methods, so how can i use it? all of them are POST methods. Can i set some parameters or some request body, or some templates. how can i improve this process.

Yes if you are mapping to an RPC API then you can build the REST methods/resources in API Gateway and set a static value for the header or in the body, wherever the RPC action is expected by the backend.

  1. How can i use API key here? or it won`t work in POST method? Because while accessing from curl, it works fine without API key.

First you should set API Key Required on the method (Method Request page), then you'll have to add the API Stage to the API Key and make sure it's enabled. After all that, if you send the API Key in a header called 'x-api-key' it should work, otherwise you should get a 403 response saying "Forbidden".

  1. If i do "curl -H "Content-Type: application/json" -X POST -d "{\"method\": \"app.menu\",\"params\":[] }" https://xxxxxxxxxxx-api.us-east-1.amazonaws.com/dev1" i get same response as i curl http://xxx.xxxxxxx.com/RPC2/. is it the only way to access my dev1 URL or i can create individual methods or string parametrs.

You will have to create each method in API Gateway (like GET) and they can all point to the same backend url but specify a different RPC action in the header or wherever it is specified.

I'd encourage you to check the public developer guides for parameter mapping and payload transformation to learn what tools we have in API Gateway.