4
votes

I'm trying to create an API using AWS API gateway

  • first I have created a resource as /sample
  • then created a method GET
  • provided Endpoint-URL and saved it.
  • In the Method Execution pane, select Method Request, added HTTP Request Headers as "Authorization" , added this to pass basic authentication details to back-end url since service is secured with basic authentication,
  • In the Method Execution pane, choose Integration Request, mapped HTTP Headers, Mapped from as "method.request.path.Authorization"
  • Choose Method Execution, and in the Client box, choose TEST, passed Header Authorization - Basic XXXXXX After finished all the configuration successfully, tested the API , getting "message": "Internal server error" status code -500

For your reference my back-end service is running in the amazon-linux machine.

Checked logs:
   Execution log for request test-request
Tue Sep 08 16:43:54 UTC 2015 : Starting execution for request: test-invoke-request
Tue Sep 08 16:43:54 UTC 2015 : API Key: test-invoke-api-key
Tue Sep 08 16:43:54 UTC 2015 : Method request path: {}
Tue Sep 08 16:43:54 UTC 2015 : Method request query string: {}
Tue Sep 08 16:43:54 UTC 2015 : Method request headers: {Authorization=************p1c2Vy}
Tue Sep 08 16:43:54 UTC 2015 : Method request body before transformations: null
Tue Sep 08 16:43:54 UTC 2015 : Execution failed due to configuration error: Invalid endpoint address

Could you please let me know how to resolve this issue?

3
You say your backend is running on amazon-linux machine, does this machine have a public IP associated with it? Is it behind an ELB?Bob Kinney

3 Answers

1
votes

try method.request.header.Authorization

1
votes

Varun is right, your mapping expression is wrong.

The expression format for parameters in the request is "method.request.[source].[name]" where source is path/querystring/header and name is the name of the parameter as defined in the method request.

For the integration response, the format is the same exception you'd replace request with response and also note that only headers are available to map in the response.

0
votes

If you want a quick fix just to start and get your API worked then follow these steps:

Steps

  • Login to AWS console
  • Go to "API Gateway" dashboard, select the resource(API) you need to invoke then select the method underneath (GET/POST/...)
  • On the method execution workflow, click on the "Method Response panel" and add status code 200 then you can add some headers for that. Choose the "Response Body" and add "Application/json" with "Empty" model.

enter image description here

  • You should also click "Integration Request panel" and uncheck "Use Lambda Proxy integration" [as per attached image]

enter image description here

Last step

  • deploy your API into the stage(dev/test/prod)