有没有人知道为什么这段代码:
import { SFNClient, StartExecutionCommand } from "@aws-sdk/client-sfn";
export const handler = async(event) => {
const ev = {
"txid": "8787878787877v423-98vh349hv34878787878787879",
"sid": "8ac36b76-e102-5e1b-ad94-5bb5e6564956",
"val": "80.0",
"cur": "USD",
"type": "s"
}
const stepFunctions = new SFNClient({region: 'us-east-1'});
let params = { input: JSON.stringify(ev), stateMachineArn: 'arn:aws:states:us-east-1:xxxxx'};
const command = new StartExecutionCommand(params);
await stepFunctions.send(command)
.then((result) => console.log(result))
.catch((er) => console.error(er.stack))
};
完美地执行step函数,但是这段代码(包含在一个普通的JS文件中,也运行node 18.x)超时了?[10秒+])
const { SFNClient, StartExecutionCommand } = require("@aws-sdk/client-sfn");
exports.handler = async (event) => {
const ev = {
"txid": "8787878787877v423-98vh349hv34878787878787879",
"sid": "8ac36b76-e102-5e1b-ad94-5bb5e6564956",
"val": "80.0",
"cur": "USD",
"type": "s"
}
let params = { input: JSON.stringify(ev), stateMachineArn: 'arn:aws:states:us-east-1:us-east-1:xxxxx'};
const command = new StartExecutionCommand(params);
await stepFunctions.send(command)
.then((result) => console.log(result))
.catch((er) => console.error(er.stack))
}
两个lambda函数都有足够的权限,尽管后面的代码片段是一个更大的函数的一部分,但所有前面的代码都可以在几秒钟内正确执行。
我完全不知所措,花了一整天的时间试图弄清楚为什么会发生这种情况。
任何建议将不胜感激!
1条答案
按热度按时间20jt8wwn1#
我认为你的代码在这两个解决方案中都是错误的。但我不能说为什么它在第一个和第二个不工作。
试着写得像
您应该
await
promise,或者在非异步函数中使用then
和catch
回调