【问题标题】:Didn't identify the httpMethod at aws Lambda function未在 aws Lambda 函数中识别 httpMethod
【发布时间】:2020-07-06 17:19:39
【问题描述】:

我正在从 aws 绑定 api,但没有识别 httpMethod 没有识别我不明白为什么会发生这种情况?我已经在 api-gateway 的 get 请求中映射了集成请求。有什么我错过的吗?

Lambda 函数如下图所示:

exports.handleHttpRequest = function (request, context, callback) {
    console.log('---------', request, request.httpMethod);
    switch (request.httpMethod) {
        case 'GET': {
        
            callback(null, "get case run");
            break;
        }
        case 'POST': {
            callback(null, "post Case run");
            break;
        }
        default:
            callback(null, "run default case");
    }
}

【问题讨论】:

    标签: javascript node.js amazon-web-services aws-lambda devops


    【解决方案1】:

    你可以在stackoverflow的这个链接中找到你的答案:

    How to get the HTTP method in AWS Lambda?

    您需要通过 API Gateway > Mapping Tempates 的上下文对象发送它。然后,您只需调用 Lambda 函数中可用的 context.httpMethod

    您可以在aws docs 找到它。

    【讨论】:

      猜你喜欢
      • 2018-04-14
      • 2021-11-06
      • 2017-11-20
      • 2017-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-31
      相关资源
      最近更新 更多