[英]Serverless, API Rest, get body on Lambda POST
I have a Lambda POST function, I'm sending a json body for testing as:我有一个 Lambda POST 函数,我正在发送一个 json 正文进行测试:
{
"id": 3
}
But I don't know how to read that body on my code.但我不知道如何在我的代码中阅读该正文。
At first I had a GET API, I called that API with:起初我有一个 GET API,我用以下命令调用该 API:
POST:https://XXX.execute-api.us-east-2.amazonaws.com/dev/getData/123 (Content-Type: application/json) POST:https ://XXX.execute-api.us-east-2.amazonaws.com/dev/getData/123 (内容类型:application/json)
so in my code I had:所以在我的代码中我有:
export const handler = async (
event: { pathParameters: { ID: any } }
): Promise<any> => {
console.log(event.pathParameters.ID) // 123
serverless.yml
was: serverless.yml
是:
functions:
feelookup:
handler: src/functions/getData.handler
events:
- http:
path: /getData
method: get
cors: true
But now I don't know how to read the body on POST但现在我不知道如何在 POST 上阅读正文
Edit: I tried by event.body
but it doesn't existe body.编辑:我通过event.body
尝试过,但它不存在身体。
Here I have console.logs of event
and args
(from CloudWatch
):这里我有event
和args
console.logs(来自CloudWatch
):
export const handler = async (
event: any,
args: any,
): Promise<any> => {
console.log('event', event);
console.log('args: ', args);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.