AWS Lambda + S3 + ffmpeg = Timelapse

by Christian Fei @ 2019-08-30

227 words, 1 minute reading time

#post #aws #js #tutorial 

this

Yes you read that right. Figured out a way to make a timelapse thanks to AWS Lambda and a bucket with images on S3.

Requirements

Deploy the ffmpeg layer

With aws lambda you can leverage an existing layer made of pre-built packages.

You can extend the ffmpeg-lambda-layer to write the Lambda with ffmpeg built in.

So to do this, deploy the Layer via the serverless repo: Click here and deploy it on AWS Lambda and copy the ARN

ffmpeg-layer.png

Create an S3 bucket

Name it, for example, "garden-snapshots" in the same region as the ffmpeg-lambda-layer

Get project

Download the project from here: github.com/christian-fei/timelapse-lambda

git clone [email protected]:christian-fei/timelapse-lambda.git

Create IAM Role

Go to IAM and create a role with the following permissions:

lambda-iam.png

Create timelapse lambda

run ./create-aws-lambda by specifying the needed parameters, below you can find an example.

in the same region as above!

./create-aws-lambda \
  --region us-east-1 \
  --lambda Timelapse \
  --role arn:aws:iam::XXXXXXXXXXX:role/lambda_name \
  --ffmpeg arn:aws:lambda:us-east-1:XXXXXXXXXXX:layer:ffmpeg:1

update the lambda with the code

specify the region and the lambda name as above and run:

./deploy-aws-lambda \
  --region us-east-1 \
  --lambda Timelapse

usage

Download the project from here: github.com/christian-fei/timelapse-lambda

git clone [email protected]:christian-fei/timelapse-lambda.git

npm install and take a look at launch-lambda-example.js:

#!/usr/bin/env node

const AWS = require('aws-sdk')

const region = 'us-east-1'

const apiVersion = 'latest'
const lambda = new AWS.Lambda({ apiVersion, region })
const invokeParams = { FunctionName: 'Timelapse' }

lambda.invoke(invokeParams, (err, data) => {
  console.log(err, data)
})

this

Leave a comment

Better web scraping with node.js My blogging stack in 2020 Run cypress integration tests with github actions workflow Simple telegram message with github actions Deploy eleventy site with github actions on aws s3 Simple ad and trackers blocking with dns Build for a slow connection Upgrade mongodb 3 to 4 on ubuntu Publishing org scoped npm packages with travis A story about npm publish / unpublish