Created
February 16, 2015 02:38
-
-
Save russau/b915c907772f2dfa2679 to your computer and use it in GitHub Desktop.
Lambda function for ElasticTranscoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('Loading event'); | |
var AWS = require('aws-sdk'); | |
exports.handler = function(event, context) { | |
console.log('Received event:'); | |
console.log(JSON.stringify(event, null, ' ')); | |
// Get the object from the event and show its content type | |
var bucket = event.Records[0].s3.bucket.name; | |
var key = event.Records[0].s3.object.key; | |
var output = Math.random().toString(36).substring(7) + ".webm"; | |
console.log("Video processing for: " + key); | |
var elastictranscoder = new AWS.ElasticTranscoder({ region : "us-east-1" }) | |
var params = { | |
Input: { /* required */ | |
AspectRatio: "auto", | |
Container: "auto", | |
FrameRate: "auto", | |
Interlaced: "auto", | |
Key: key, | |
Resolution: "auto" | |
}, | |
PipelineId: "1423975421228-rxhwv2", /* required */ | |
OutputKeyPrefix: "s3demo/", | |
Outputs: [ | |
{ | |
Key: output, | |
PresetId: "1423984395335-y4axq4", | |
Rotate: "auto", | |
Watermarks: [ | |
{ | |
InputKey: "webm.png", | |
PresetWatermarkId: "BottomRight" | |
}, | |
] | |
}, | |
], | |
Playlists: [], | |
UserMetadata: {} | |
}; | |
elastictranscoder.createJob(params, function(err, data) { | |
if (err) { | |
console.log('error processing ' + key ); | |
context.done('error','error processing '+err); | |
} | |
else { | |
console.log(data); | |
context.done(null,''); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment