【问题标题】:Unexpected end of JSON input error in AWS Lambda SQS functionAWS Lambda SQS 函数中 JSON 输入错误意外结束
【发布时间】:2021-03-27 23:58:13
【问题描述】:

这是我的 nodejs 应用无服务器 lambda 函数

export const updateDailyForecastResults: SQSHandler = async (event) => {
  console.log('Function invoked!!!!');
  await env.check();
  event.Records.forEach(record => {
    const { body } = record;
    console.log(body);
  });
  return;
}; 

我发送的是文档示例 sqs 事件

{
  "Records": [
    {
      "messageId": "059f36b4-87a3-44ab-83d2-661975830a7d",
      "receiptHandle": "AQEBwJnKyrHigUMZj6rYigCgxlaS3SLy0a...",
      "body": "test",
      "attributes": {
        "ApproximateReceiveCount": "1",
        "SentTimestamp": "1545082649183",
        "SenderId": "AIDAIENQZJOLO23YVJ4VO",
        "ApproximateFirstReceiveTimestamp": "1545082649185"
      },
      "messageAttributes": {},
      "md5OfBody": "098f6bcd4621d373cade4e832627b4f6",
      "eventSource": "aws:sqs",
      "eventSourceARN": "arn:aws:sqs:us-east-2:123456789012:my-queue",
      "awsRegion": "us-east-2"
    }
  ]
}

或者我尝试了其他版本的 Json 对象,但总是遇到同样的错误

{
  "errorType": "Runtime.UserCodeSyntaxError",
  "errorMessage": "SyntaxError: Unexpected end of JSON input",
  "trace": [
    "Runtime.UserCodeSyntaxError: SyntaxError: Unexpected end of JSON input",
    "    at _loadUserApp (/var/runtime/UserFunction.js:98:13)",
    "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
    "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
    "    at Module._compile (internal/modules/cjs/loader.js:1015:30)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)",
    "    at Module.load (internal/modules/cjs/loader.js:879:32)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:724:14)",
    "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
    "    at internal/main/run_main_module.js:17:47"
  ]
}

谁能帮帮我?

【问题讨论】:

标签: node.js json aws-lambda amazon-sqs


【解决方案1】:

这个异常意味着你的代码有语法错误。

它发生在处理事件之前,所以你给它什么事件并不重要。

你能分享所有代码(和依赖项)吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-26
    • 1970-01-01
    • 1970-01-01
    • 2016-11-13
    • 1970-01-01
    相关资源
    最近更新 更多