How do I pass arguments to AWS Lambda functions using GET requests?

前端 未结 2 1126
误落风尘
误落风尘 2021-02-02 10:30

Say I want to pass val1 and val2 in the URL string when making a GET request from my Api gateway endpoint to my Lambda function:

https://xyz.execute-api.amazonaw         


        
2条回答
  •  心在旅途
    2021-02-02 10:52

    After defining the query string parameters in Method Request section of the API Gateway, you then need to define a Mapping Template in the Method Execution section.

    In the Method Execution section, select Mapping Templates and then click Add Mapping Template. Enter application/json for the Content Type and then create a mapping template that looks something like this:

    {
        "va1": "$input.params('val1')",
        "val2": "$input.params('val2')"
    }
    

    This will tell API Gateway to take the input parameters (either passed on the path, or in headers, or in query parameters) called val1 and val2 and send them to the Lambda function in the event data as val1 and val2.

提交回复
热议问题