【发布时间】: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"
]
}
谁能帮帮我?
【问题讨论】:
-
这个 lambda 是通过 API 网关调用的吗?如果是,则应遵循响应格式:docs.aws.amazon.com/apigateway/latest/developerguide/…
标签: node.js json aws-lambda amazon-sqs