0

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.

Community
  • 1
  • 1
Peter
  • 1,053
  • 13
  • 29
  • Can you post your Lambda log without sensitive details? Also I have used the code from [this tutorial](http://fartashh.github.io/post/serverless-approach-to-transcode-media/) and with some adjustments worked. – manuel Sep 03 '16 at 20:47
  • @manuel changed my code to that tutorial. Still nothing happens – Peter Sep 03 '16 at 22:47
  • Does the role have permissions to create a Elastic Transcoder job? With the code from my tutorial should have worked or at least given you a more clear error log. – manuel Sep 04 '16 at 09:01
  • @manuel Yes, my role permissions are above. Including createJob permissions. – Peter Sep 05 '16 at 19:36
  • @manuel I added a `Bucket` to input param, with the event bucket name. Although this is wrong and I get an error, I do get a log "made job" which is inside the transcoder create job block. With just key in input params, "made job" never gets called – Peter Sep 05 '16 at 20:09
  • Did you place the Lambda function inside a VPC that doesn't have a NAT Gateway? If so, you should probably move it out of the VPC since you don't appear to be doing anything that would require VPC access. – Mark B Jan 03 '17 at 22:25

1 Answers1

0

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.

Kev
  • 312
  • 3
  • 11
  • "No VPC" literally means no VPC. It doesn't mean "default VPC". Lambda functions can't access resources outside a VPC unless the VPC has a NAT Gateway. This is because Lambda functions inside a VPC don't get a public IP address. – Mark B Jan 03 '17 at 22:24