Amazon ElasticTranscoder, 如何等待作业完成?



我有一个node.js lambda,在S3事件上触发。Elastic Transcoder作业的启动方式如下:

let AWS = require('aws-sdk');
let s3 = new AWS.S3({apiVersion: '2012–09–25'});
let eltr = new AWS.ElasticTranscoder({apiVersion: '2012–09–25', region: 'us-west-2'});
exports.handler = (event, context, callback) => {
    let pipelineId = 'keystone';
    let bucket = event.Records[0].s3.bucket.name;
    let key = event.Records[0].s3.object.key;
    let etParams = {
        PipelineId: pipelineId,
        Input: {
            Key: key,
            FrameRate: 'auto',
            Resolution: 'auto',
            AspectRatio: 'auto',
            Interlaced: 'auto',
            Container: 'auto'
        },
        Outputs: [{
            Key: key,
            PresetId: '1351620000001-000010'
        }]
    };
    eltr.createJob(etParams, function(err, data) {
        if (err) {
            console.log("ET error", err, err.stack);
        } else {
            console.log("Calling waitFor for Job Id:", data.Job.Id);
            eltr.waitFor("jobComplete", {Id: data.Job.Id}, function(err, data) {
                if (err) {
                    console.log("ET waitFor Error", err, err.stack);
                } else {
                    console.log("ET Job finished", data, data.Job.Output.Key);
                }
            });
        }   
    });
};

transcoding过程times out

START RequestId: 82c0a1ce-5cf3-11e7-81aa-a3362402de83 Version: $LATEST
2017-06-29T17:51:03.509Z    82c0a1ce-5cf3-11e7-81aa-a3362402de83    Creating Job { PipelineId: 'keystone',
Input: 
{ Key: 'f04d62af47.mp4',
FrameRate: 'auto',
Resolution: 'auto',
AspectRatio: 'auto',
Interlaced: 'auto',
Container: 'auto' },
Outputs: 
[ { Key: 'f04d62af47.mp4',
PresetId: '1351620000001-000010' } ] }
2017-06-29T17:51:04.829Z    82c0a1ce-5cf3-11e7-81aa-a3362402de83    Calling waitFor for Job Id: 1498758664450-jxhdlx
END RequestId: 82c0a1ce-5cf3-11e7-81aa-a3362402de83
REPORT RequestId: 82c0a1ce-5cf3-11e7-81aa-a3362402de83  Duration: 3001.65 ms    Billed Duration: 3000 ms Memory Size: 128 MB    Max Memory Used: 37 MB  
2017-06-29T17:51:06.260Z 82c0a1ce-5cf3-11e7-81aa-a3362402de83 Task timed out after 3.00 seconds

上面的日志输出重复了 3 次(lambda 的三次尝试?

我确定我错过了一些东西,有人可以指出错误吗?

对 AWS Lambda 进行的所有调用必须在 300 秒内完成执行。默认超时为 3 秒,但您可以将超时设置为 1 到 300 秒之间的任何值。

根据你的两次重试猜想,你是对的。如果 AWS Lambda 无法完全处理异步事件,则它将自动重试调用两次,并在重试之间出现延迟。

最新更新