首页 文章

调用API错误 - AWS API网关

提问于
浏览
4

我正在尝试使用AWS API网关创建API

  • 首先我创建了一个资源/ sample

  • 然后创建了一个方法GET

  • 提供了Endpoint-URL并保存了它 .

  • 在“方法执行”窗格中,选择“方法请求”,将“HTTP请求标头”添加为"Authorization",添加此项以将基本身份验证详细信息传递给后端URL,因为服务是通过基本身份验证保护的,

  • 在“方法执行”窗格中,选择“集成请求”,“映射的HTTP标头”,“从"method.request.path.Authorization"映射”

  • 选择方法执行,在客户端框中,选择TEST,传递Header Authorization - Basic XXXXXX成功完成所有配置后,测试API,获取"message":"Internal server error"状态代码-500

供您参考我的后端服务是在amazon-linux机器上运行的 .

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

你能告诉我如何解决这个问题吗?

3 回答

  • 0

    尝试method.request . header . 授权

  • 1

    Varun是对的,你的映射表达式是错误的 .

    请求中参数的表达式格式为“method.request . [source] . [name]”,其中source是path / querystring / header,name是方法请求中定义的参数名称 .

    对于集成响应,格式是您使用响应替换请求的相同异常,并且还要注意只有标头可用于在响应中进行映射 .

  • 1

    如果您想要快速修复以启动并使您的API工作,请按照以下步骤操作:

    步骤

    • 登录AWS控制台

    • 转到"API Gateway"仪表板,选择需要调用的资源(API),然后选择下面的方法(GET / POST / ...)

    • 在方法执行工作流程上,单击"Method Response panel"并添加状态代码200,然后您可以为其添加一些 Headers . 选择"Response Body"并使用"Empty"模型添加"Application/json" .

    enter image description here

    • 您还应该单击"Integration Request panel"并取消选中"Use Lambda Proxy integration" [根据附图]

    enter image description here

    最后一步

    • deploy your API 进入舞台(dev / test / prod)

相关问题