Search code examples
aws-cloudformationaws-api-gatewayaws-cdk

Adding parameters to api using cloudformation


I tried the cloudformation template that I found here... https://bl.ocks.org/magnetikonline/c314952045eee8e8375b82bc7ec68e88

It works as expected. But I will like to provide parameters to the post request. My Curl command should look something like this...

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

How do I handle it at API gateway in the cloudformation template? I have already set the environment variable at lambda function level.


The template that does not work is this...

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

As it is clear that I am not able to pass the "mnumber" variable through the gateway.


I have updated my template and now it deploys function and gateway corretly. And still the URL generated does not work and shows "internal server error" message.

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


Solution

  • You should change to using HTTP proxy integration. Here is some info from AWS on proxy integration: https://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-http-integrations.html

    Try changing your RequestParameters from:

    RequestParameters:
            method.request.querystring.mnumber: false
    

    to

    RequestParameters:
            method.request.path.proxy: true
    

    and under integration from:

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

    to

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

    This is a good tutorial on proxy integration with API Gateway: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-http.html