我一直在使用状态机来生成 pdf。问题是它运行良好,但在 7 月 23 日它自动停止工作。我的第一步被成功调用,但没有将数据传递到下一步并超时。
- 尝试增加超时它不起作用。
- 尝试增加“StateTransition 节流令牌桶大小”的配额,它也没有用
- 日志显示该步骤中的完整执行,但是当通过回调将数据发送到下一步时,lambda 会出现超时错误。
在下面附加我的 lambda 函数。
'use strict'
var db = require('database-layer');
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
exports.lambdaHandler = (event, context, callback) => {
console.log(event);
const bucket = process.env['S3_BUCKET_NAME'] || '';
// This will allow us to freeze open connections to a database
var data = event;
var blogPayload = data.sqsPayload
try {
db.helpers.blogHelper.findHelper({_id: blogPayload._id, type: 'BLOG'}, (_, res) => {
if(res.data){
// create html file and send s3 uri
let newHtmlContent = res.data.content + embedSignatureInHtml(data.sqsPayload.signaturePayload);
newHtmlContent = `<!DOCTYPE html><html><head><meta charset="UTF-8"></head><body style="font-family: Dejavu Sans;">${newHtmlContent}</body></html>`
var lambdaRequestId = context.awsRequestId;
const output_filename = `html-file/${lambdaRequestId.replace(/\.[^.]+$/, '')}.html`
const s3PutParams = {
Bucket: bucket,
Key: output_filename,
Body: newHtmlContent,
ContentType: 'text/html',
Metadata: { "x-amz-meta-requestId": lambdaRequestId }
};
s3.upload(s3PutParams, function(error, uploadData) {
if ( error ) {
console.error('s3:putObject failed!');
callback(null, {
'isAllowed': false,
'sqsQueData': data.sqsQueData
});
return;
}
console.log(uploadData, ' data found and uploaded successfully.');
callback(null, {
'isAllowed': true,
'sqsQueData': data.sqsQueData,
'sqsPayload': data.sqsPayload,
'uploadedHtmlUri': process.env.APP_CDN + uploadData.Key,
});
});
} else {
console.log('data not found', res)
callback(null, {
'isAllowed': false,
'sqsQueData': data.sqsQueData
});
}
});
}catch (e) {
console.log(e.toString());
callback(null, {
'isAllowed': false,
'sqsQueData': data.sqsQueData
});
}
}
这是状态机定义,以前工作得很好,但现在不知何故崩溃了。
{
"Comment": "A state machine that generates pdf and update the system",
"StartAt": "Check Proposal",
"States": {
"Check Proposal": {
"Type": "Task",
"Resource": "${CheckProposalFunctionArn}",
"Retry": [
{
"ErrorEquals": [
"States.TaskFailed"
],
"IntervalSeconds": 2,
"MaxAttempts": 0,
"BackoffRate": 1.5
}
],
"Next": "Generate Or Not?"
},
"Generate Or Not?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.isAllowed",
"BooleanEquals": true,
"Next": "Generate Pdf"
}
],
"Default": "Update SQS"
},
"Generate Pdf": {
"Type": "Task",
"Resource": "${GeneratePdfFunctionArn}",
"Retry": [
{
"ErrorEquals": [
"States.TaskFailed"
],
"IntervalSeconds": 2,
"MaxAttempts": 1,
"BackoffRate": 1
}
],
"Next": "Update Or Not?"
},
"Update Or Not?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.isAllowed",
"BooleanEquals": true,
"Next": "Update Pdf"
}
],
"Default": "Update SQS"
},
"Update Pdf": {
"Type": "Task",
"Resource": "${UpdatePdfUrlFunctionArn}",
"Retry": [
{
"ErrorEquals": [
"States.TaskFailed"
],
"IntervalSeconds": 2,
"MaxAttempts": 1,
"BackoffRate": 1
}
],
"Next": "Update SQS"
},
"Update SQS": {
"Type": "Task",
"Resource": "${UpdateSQSFunctionArn}",
"Retry": [
{
"ErrorEquals": [
"States.TaskFailed"
],
"IntervalSeconds": 2,
"MaxAttempts": 2,
"BackoffRate": 1
}
],
"End": true
}
}
}