gpt4 book ai didi

amazon-web-services - AWS lambda : invoke function via other lambda function

转载 作者:行者123 更新时间:2023-12-04 08:19:27 26 4
gpt4 key购买 nike

我有一个 AWS Lambda 函数,需要大约 30 秒。当我将它连接到 API 网关时,由于 5 秒超时,它正在发送 504。所以我的 easyCron 作业失败了,不会再试一次(我只有一个免费计划)

所以我需要一个 API,它可以发送正确的 200 状态。我的想法:

通过短期 lambda 调用长期 lambda。该策略允许调用。

这是代码

var AWS = require('aws-sdk'),

params = {
FunctionName: 'cctv',
InvocationType: 'RequestResponse',
LogType: 'Tail'
},
lambda;
AWS.config.update({region: 'us-east-1'});
lambda = new AWS.Lambda();

exports.handler = function (event, context) {
'use strict';
lambda.invoke(params, function (err, data) {
if (err) {
console.log(err, err.stack);
}
else {
console.log(data);
}
});
context.succeed('hey cron job, I think my lambda function is not called');

};

但我认为,context.succeed() 中止了 lambda.invoke()

的执行

你知道如何解决这个问题吗?

最佳答案

这是不正确的

InvocationType: 'RequestResponse'

你应该使用

InvocationType: 'Event'

来自 http://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestSyntax

By default, the Invoke API assumes "RequestResponse" invocation type. You can optionally request asynchronous execution by specifying "Event" as the InvocationType.

关于amazon-web-services - AWS lambda : invoke function via other lambda function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32780476/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com