Created
June 18, 2018 05:40
-
-
Save lukehoban/d638ffc3f8067e66fb5df8c761289c0f to your computer and use it in GitHub Desktop.
Serverless + Containers with Pulumi
This file contains hidden or 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
const cloud = require("@pulumi/cloud-aws"); | |
const aws = require("@pulumi/aws"); | |
// A bucket to store videos and thumbnails. | |
const bucket = new cloud.Bucket("bucket"); | |
const bucketName = bucket.bucket.id; | |
// A task which runs a containerized FFMPEG job to extract a thumbnail image. | |
const ffmpegThumbnailTask = new cloud.Task("ffmpegThumbTask", { | |
build: "./docker-ffmpeg-thumb", | |
memoryReservation: 512, | |
}); | |
// When a new video is uploaded, run the FFMPEG task on the video file. | |
// Use the time index specified in the filename (e.g. cat_00-01.mp4 uses timestamp 00:01) | |
bucket.onPut("onNewVideo", bucketArgs => { | |
console.log(`*** New video: file ${bucketArgs.key} was uploaded at ${bucketArgs.eventTime}.`); | |
const file = bucketArgs.key; | |
const thumbnailFile = file.substring(0, file.indexOf('_')) + '.jpg'; | |
const framePos = file.substring(file.indexOf('_')+1, file.indexOf('.')).replace('-',':'); | |
ffmpegThumbnailTask.run({ | |
environment: { | |
"S3_BUCKET": bucketName.get(), | |
"INPUT_VIDEO": file, | |
"TIME_OFFSET": framePos, | |
"OUTPUT_FILE": thumbnailFile, | |
}, | |
}).then(() => { | |
console.log(`Running thumbnailer task.`); | |
}); | |
}, { keySuffix: ".mp4" }); | |
// When a new thumbnail is created, log a message. | |
bucket.onPut("onNewThumbnail", bucketArgs => { | |
console.log(`*** New thumbnail: file ${bucketArgs.key} was saved at ${bucketArgs.eventTime}.`); | |
return Promise.resolve(); | |
}, { keySuffix: ".jpg" }); | |
// Export the bucket name. | |
exports.bucketName = bucketName; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment