Create AWS Transcoder job from Lambda

不打扰是莪最后的温柔 提交于 2019-12-22 01:04:41

问题


I've created a Lambda function that is called with every new s3 object creation. I'm trying to retrieve the object, then create a new Transcoder job that alters the video quality. But the transcoder job is never created. creating job.... shows up but job created never appears in my logs.

Going off of this tutorial.

My Lambda Function:

 var aws = require('aws-sdk');
 var elastictranscoder = new aws.ElasticTranscoder();

exports.handler = function(event, context) {
    console.log('Got Video:', JSON.stringify(event, null, 2));

    // Get the object from the event and show its content type
    var key = event.Records[0].s3.object.key;
    console.log('Key:', key);
    var params = {
       Input: { 
          Key: key
       },
       PipelineId: 'xxx', 
       OutputKeyPrefix: 'output/',
       Outputs: [
        {
           Key: outputKey(basename(key),'mp4'),
           PresetId: '1441222625682-nnthmh', // h264
        },
      {
         Key: outputKey(basename(key),'webm'),
         PresetId: '1441222599518-vt9jbu', // webm
        }
      ]
    };

    console.log('creating job....');

    elastictranscoder.createJob(params, function(err, data) {
       console.log('job created');
       if (err){
         console.log('ERROR...',err, err.stack); // an error occurred
         context.fail();
         return;
       }else{
         console.log('created job successfully');
       }
       context.succeed();
    });
};

I thought it might have something to do with my Lambda role but I'm pretty sure every thing is good. Cloud and transcoder: createJob access.

{
  "Version": "2012-10-17",
  "Statement": [
    {
       "Effect": "Allow",
         "Action": [
           "logs:CreateLogGroup",
           "logs:CreateLogStream",
           "logs:PutLogEvents"
      ],
  "Resource": "arn:aws:logs:*:*:*"
  },
   {
     "Effect": "Allow",
       "Action": [
         "s3:GetObject",
         "s3:PutObject"
        ],
    "Resource": [
       "arn:aws:s3:::*"
     ]
  },
  {
        "Effect": "Allow",
        "Action": [
            "elastictranscoder:Read*",
            "elastictranscoder:List*",
            "elastictranscoder:*Job",
            "elastictranscoder:CreateJob",
            "elastictranscoder:*Preset",
            "s3:List*",
            "sns:List*"
        ],
        "Resource": "*"
    }
   ]
 }

EDIT Changed to this tutorial. Heres the new code

 'use strict';
 console.log('Loading function');

 let aws = require('aws-sdk');
 let s3 = new aws.S3({ apiVersion: '2006-03-01' });
 let elastictranscoder = new aws.ElasticTranscoder();


 function getFileName(path) {
     return path.split('/').reverse()[0].split('.')[0];
 }


 exports.handler = (event, context, callback) => {
   //  const bucket = event.Records[0].s3.bucket.name;
     const key = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' '));

     var params = {
          Input: { 
          Key: key
     },
     PipelineId: 'xxx', 
     OutputKeyPrefix: 'files/',
     Outputs: [
         {
             Key: getFileName(key),
             PresetId: '1351620000001-200060', // hls
        }
         ]
     };
     console.log('loading transcoder');
     elastictranscoder.createJob(params, function(err, data) {
         console.log('made job');
         if (err){
             console.log(err, err.stack); // an error occurred
             context.fail();
             return;
         }
         context.succeed();
     });
 };

In the logs I get

Loading function

START RequestId: xxx Version: $LATEST

loading transcoder

END RequestId: xxx

REPORT RequestId: xxx

Task timed out after 3.00 seconds

The create job block is never called.


回答1:


Under the VPC drop down i had to choose "No VPC" for this to work - i.e. let it run inside the "default system-managed VPC", once I changed that they worked instantly.



来源:https://stackoverflow.com/questions/39277782/create-aws-transcoder-job-from-lambda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!