Node.js AWS Lambda随机超时
我们创建了一个名为-execInspector的基于NodeJS的Lambda函数,该函数每天触发一次。此函数是基于NodeJS中的AWS Lambda blueprint-->“inspector计划运行”创建的 我们看到的问题是计划的作业某天或某天随机失败。我们仅从cloudwatch日志流中获取以下日志 在一周内,它会随机运行约4/5次,并在剩余的几天内失败。根据日志,它的执行只消耗很少的内存/时间,但不确定它随机失败的原因。它也会在被杀死之前重试3次 从下面的日志中,我们还可以发现该作业平均只需要35 MB,平均只需要60秒就可以完成。我们尝试修改NodeJ的运行时间,增加内存,超时远远超过此限制,但没有任何效果 如果有人知道为什么会发生这种情况,你能提供一些替代方法来自动处理这些故障吗 其他投入: 我们已经给出了5分钟的最大超时时间,但它没有说“300秒后超时” 我在这里的意思是,触发检查器的任务在avg上只需要不到30秒的时间。因为它是一个基于PaaS的解决方案,我不能期望它总是在30秒内完成。但是60秒应该足够处理一个30秒内就能完成的任务 CloudWatch成功日志示例: 18:01:00 启动请求ID:12eb468a-4174-11e7-be7b-6d0faaa584aa版本:$LATEST 18:01:03 2017-05-25T18:01:02.935Z 12eb468a-4174-11e7-be7b-6d0faaa584aa{评估RUNARN:'arn:aws:inspector:us-east-1:102461617910:target/0-Ly60lmEP/template/0-POpZxSLA/run/0-MMx30fLl'} 2017-05-25T18:01:02.935Z 12eb468a-4174-11e7-be7b-6d0faaa584aa{评估RUNARN:'arn:aws:inspector:us-east-1:102461617910:target/0-Ly60lmEP/template/0-POpZxSLA/run/0-MMx30fLl'} 18:01:03 结束请求ID:12eb468a-4174-11e7-be7b-6d0faaa584aa 结束请求ID:12eb468a-4174-11e7-be7b-6d0faaa584aa 18:01:03 报告请求ID:12eb468a-4174-11e7-be7b-6d0faaa584aa持续时间:2346.37毫秒计费持续时间:2400毫秒内存大小:128 MB最大使用内存:33 MB 报告请求ID:12eb468a-4174-11e7-be7b-6d0faaa584aa持续时间:2346.37毫秒计费持续时间:2400毫秒内存大小:128 MB最大使用内存:33 MB Cloudwatch日志:Node.js AWS Lambda随机超时,node.js,amazon-web-services,lambda,Node.js,Amazon Web Services,Lambda,我们创建了一个名为-execInspector的基于NodeJS的Lambda函数,该函数每天触发一次。此函数是基于NodeJS中的AWS Lambda blueprint-->“inspector计划运行”创建的 我们看到的问题是计划的作业某天或某天随机失败。我们仅从cloudwatch日志流中获取以下日志 在一周内,它会随机运行约4/5次,并在剩余的几天内失败。根据日志,它的执行只消耗很少的内存/时间,但不确定它随机失败的原因。它也会在被杀死之前重试3次 从下面的日志中,我们还可以发现该作业
'use strict';
/**
* A blueprint to schedule a recurring assessment run for an Amazon Inspector assessment template.
*
* This blueprint assumes that you've already done the following:
* 1. onboarded with the Amazon Inspector service https://aws.amazon.com/inspector
* 2. created an assessment target - what hosts you want to assess
* 3. created an assessment template - how you want to assess your target
*
* Then, all you need to do to use this blueprint is to define an environment variable in the Lambda console called
* `assessmentTemplateArn` and provide the template arn you want to run on a schedule.
*/
const AWS = require('aws-sdk');
const inspector = new AWS.Inspector();
const params = {
assessmentTemplateArn: process.env.assessmentTemplateArn,
};
exports.handler = (event, context, callback) => {
try {
// Inspector.StartAssessmentRun response will look something like:
// {"assessmentRunArn":"arn:aws:inspector:us-west-2:123456789012:target/0-wJ0KWygn/template/0-jRPJqnQh/run/0-Ga1lDjhP"
inspector.startAssessmentRun(params, (error, data) => {
if (error) {
console.log(error, error.stack);
return callback(error);
}
console.log(data);
return callback(null, data);
});
} catch (error) {
console.log('Caught Error: ', error);
callback(error);
}
};
下面的类似日志重复了3次,这似乎是一次重试尝试
06:32:52
启动请求ID:80190395-404a-11e7-845d-1f88a00ed4f3版本:$LATEST
06:32:56
2017-05-24T06:32:55.942Z 80190395-404a-11e7-845d-1f88a00ed4f3开始执行。。。
06:33:52
结束请求ID:80190395-404a-11e7-845d-1f88a00ed4f3
06:33:52
报告请求ID:80190395-404a-11e7-845d-1f88a00ed4f3持续时间:60000.88毫秒计费持续时间:60000毫秒内存大小:128 MB最大使用内存:32 MB
06:33:52
2017-05-24T06:33:52.437Z 80190395-404a-11e7-845d-1f88a00ed4f3任务在60秒后超时
2017-05-24T06:33:52.437Z 80190395-404a-11e7-845d-1f88a00ed4f3任务在60秒后超时
Lambda代码:
'use strict';
/**
* A blueprint to schedule a recurring assessment run for an Amazon Inspector assessment template.
*
* This blueprint assumes that you've already done the following:
* 1. onboarded with the Amazon Inspector service https://aws.amazon.com/inspector
* 2. created an assessment target - what hosts you want to assess
* 3. created an assessment template - how you want to assess your target
*
* Then, all you need to do to use this blueprint is to define an environment variable in the Lambda console called
* `assessmentTemplateArn` and provide the template arn you want to run on a schedule.
*/
const AWS = require('aws-sdk');
const inspector = new AWS.Inspector();
const params = {
assessmentTemplateArn: process.env.assessmentTemplateArn,
};
exports.handler = (event, context, callback) => {
try {
// Inspector.StartAssessmentRun response will look something like:
// {"assessmentRunArn":"arn:aws:inspector:us-west-2:123456789012:target/0-wJ0KWygn/template/0-jRPJqnQh/run/0-Ga1lDjhP"
inspector.startAssessmentRun(params, (error, data) => {
if (error) {
console.log(error, error.stack);
return callback(error);
}
console.log(data);
return callback(null, data);
});
} catch (error) {
console.log('Caught Error: ', error);
callback(error);
}
};
日志显示您的请求在60秒后超时。根据这一点,您可以将其设置为高达5分钟,如果您的任务需要约60秒,超时时间为60秒,则可能有一些任务超时。这就是日志给我的建议。否则,请从函数中发布一些代码请参考我上面添加的详细信息。你知道这一点吗?