【发布时间】:2020-11-27 19:30:19
【问题描述】:
我正在使用 AWS Amplify 在 AWS 中构建一些后端乐趣,并且我有一个 Lambda 函数,该函数从 DynamoDB 的更新中触发。它不需要返回任何东西。
我在 CloudWatch 中不断收到错误消息,提示“SyntaxError:await 仅在异步函数中有效”。还有其他方法可以在处理程序中运行这些异步函数吗?
exports.handler = async (event) => {
console.log(JSON.stringify(event, null, 2));
event.Records.forEach(record => {
console.log(record.eventID);
console.log(record.eventName);
console.log('DynamoDB Record: %j', record.dynamodb);
if (record.eventName == "INSERT") {
try {
res = await axios.get("https://google.com", {});
console.log(res);
}
catch(e){
console.log(e);
}
}
});
};
【问题讨论】:
标签: node.js amazon-web-services asynchronous aws-lambda axios