使用Sam CLI开发AWS无服务器Express应用程序时出错

时间:2018-08-07 09:56:03

标签: amazon-web-services express aws-lambda serverless aws-sam-cli

每当我以http://127.0.0.1:3000/ get方法访问项目的本地URL时,都会收到如下错误:

2018/08/07 15:19:41 Invoking index.handler (nodejs4.3)
2018/08/07 15:19:42 Mounting /e/serverless/sanlamFundRisk as /var/task:ro inside runtime container
←[32mSTART RequestId: b4539898-148e-174b-a4f8-fdfccaaa4381 Version: $LATEST←[0m
←[31mUnable to import module 'index': Error←[0m
←[31m    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)←[0m
←[32mEND RequestId: b4539898-148e-174b-a4f8-fdfccaaa4381←[0m
←[32mREPORT RequestId: b4539898-148e-174b-a4f8-fdfccaaa4381     Duration: 17.25 ms      Billed Duration: 100 ms Memory Size: 128 MB     Max Memory Used: 23 MB     ←[0m

2018/08/07 15:19:48 ←[31mFunction returned an invalid response (must include one of: body, headers or statusCode in the response object): %!s(<nil>)
←[0m

1 个答案:

答案 0 :(得分:0)

将API Gateway与Lambda代理集成一起使用时,Lambda函数需要返回a response with a specific format

示例:

  return {
    "isBase64Encoded": false,
    "statusCode": 200,
    "headers": {
      'Content-Type:': 'application/json'
    },
    "body": JSON.stringify({
        "example": "hello"
    })
  }