markdown AWS API网关映射

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown AWS API网关映射相关的知识,希望对你有一定的参考价值。

### Lambda

First let's take a look at the data our Lambda is expecting:

```JSON
{
  "Animal": "Cat",
  "Color": "Blue"
}
```

### GET

Now, we can take a look at how to Map a GET API to these parameters

Under the Integration Request of the API, make sure the "Use Lambda Proxy integration" checkbox is **Unchecked**.

Now, under Body Mapping Templates at the bottom,
add a new Mapping Template with "When there are no templates defined (recommended)"
as the selected pass-through functionality and ```application/json``` as the Content-Type.

Then, under the template put the following:

```JSON
{
  "Animal": "$input.params('Animal')",
  "Color": "$input.params('Color')"
}
```

This means that anyone calling your API will be able to use ```?Animal=Cat&Color=Blue``` to pass parameters to your Lambda function.

### POST

A POST is largely the same as a GET method, so follow that example up until we build up the template.

For a POST, the template should look like this:

```JSON
$input.body
```

I know this looks silly, but that's really it. Because a POST comes with a body, as long as that body is in the right format,
we can pass it directly to the Lambda function. Now if this body doesn't match, then we have to get a little more creative.

Calling the API simply means that you would include the following in the body to supply parameters directly to the Lambda function:

```JSON
{
  "Animal": "Cat",
  "Color": "Blue"
}
```

以上是关于markdown AWS API网关映射的主要内容,如果未能解决你的问题,请参考以下文章

如何将AWS API网关阶段指向特定的lambda函数别名?

具有静态 IP 的 AWS API 网关

AWS Api 网关:缺少身份验证令牌

AWS cloudformation 域名和 API 映射

从 AWS API Gateway 自定义域映射中删除映射路径

AWS API Gateway - 如何在正文映射模板中获取日期/时间戳/纪元?