【问题标题】:Adding parameters to api using cloudformation使用 cloudformation 向 api 添加参数
【发布时间】:2019-12-01 14:43:05
【问题描述】:

我尝试了在这里找到的 cloudformation 模板... https://bl.ocks.org/magnetikonline/c314952045eee8e8375b82bc7ec68e88

它按预期工作。但我想为发布请求提供参数。我的 Curl 命令应该看起来像这样......

curl -d "mynumber=12345" -X POST https://tyin2sswj2.execute-api.us-east-1.amazonaws.com/mycall

如何在cloudformation模板中的API网关处理?我已经在 lambda 函数级别设置了环境变量。


不起作用的模板是这个……

https://raw.githubusercontent.com/shantanuo/cloudformation/master/updated/lambda_api.tpl.txt

很明显,我无法通过网关传递“mnumber”变量。


我已经更新了我的模板,现在它正确地部署了功能和网关。仍然生成的 URL 不起作用并显示“内部服务器错误”消息。

https://raw.githubusercontent.com/shantanuo/cloudformation/master/testapi.tpl.txt

【问题讨论】:

    标签: amazon-cloudformation aws-api-gateway aws-cdk


    【解决方案1】:

    您应该改为使用 HTTP 代理集成。 以下是 AWS 关于代理集成的一些信息:https://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-http-integrations.html

    尝试将您的 RequestParameters 更改为:

    RequestParameters:
            method.request.querystring.mnumber: false
    

    RequestParameters:
            method.request.path.proxy: true
    

    并在集成中:

    RequestParameters:
            integration.request.querystring.mnumber: "method.request.querystring.mnumber"
    

    RequestParameters:
              integration.request.path.proxy: 'method.request.path.proxy'
    

    这是一个很好的关于代理与 API Gateway 集成的教程: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-http.html

    【讨论】:

    • 感谢您的回复。但它仍然无法正常工作。我已经更新了我的问题。
    • 当您说生成的 URL 显示“内部服务器错误”时,您能否详细说明您在哪里看到的?您是到达 lambda 函数还是在到达 lambda 函数之前发生错误?
    • 将 GET 更改为 POST 解决了该问题。 forums.aws.amazon.com/thread.jspa?threadID=209420这个模板是否可以使用CDK,以便在python中易于管理?
    • 是的,这里是 Python 的 CDK API 参考链接:docs.aws.amazon.com/cdk/api/latest/python/index.html,更具体地说,是 API 网关部分:docs.aws.amazon.com/cdk/api/latest/python/…
    • 感谢您的链接。但是您能否展示一个使用 python 实现此问题中提到的相同概念的示例?
    猜你喜欢
    • 2019-07-05
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 2016-04-13
    • 1970-01-01
    • 2019-07-04
    相关资源
    最近更新 更多