alectrocute / cloud-watch-folder

Example AWS Lambda function for kicking off a Zencoder transcoding job when files are added to an S3 bucket.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Watch Folders in the Cloud

Automated transcoding using AWS S3, Lambda, and Zencoder

This is the short version of a more granular walkthrough.

This example shows how to create a cloud-based watch folder. When a new file is added to an AWS S3 bucket, it will trigger an AWS Lambda function (lambda_function.py), which makes an API call to start a Zencoder transcoding job.

  1. Create an S3 Bucket (or use an existing one).
  2. Create input and output folders within the bucket (i.e. "inputs/" and "outputs/").
  3. Give Zencoder access to the bucket using one of two methods:
  • Edit your S3 bucket's policy to grant Zencoder's IAM user access to the bucket using the provided example; be sure to replace YOUR-BUCKET with the name of the S3 bucket you're using.
  • Alternatively, create an IAM user within your AWS account, grant it access to your S3 bucket, and add that user's access keys to the credentials section of your Zencoder account.
  1. Create a new Lambda function and paste the contents of lambda_function.py into the Lambda function code area.
  2. Update the global vars at the top:
  • API_KEY is your Zencoder API key
  • INPUT_FOLDER_NAME is the name of the input folder in your S3 bucket
  • S3_OUTPUT_BASE_URL includes the output bucket and folder
  • NOTIFICATION_EMAIL is an email address where you'd like to receive job notifications (omit line 39 of the function if you don't want notifications)
  1. Optionally modify the output settings to output your preferred formats.
  2. Create a new event source for the Lambda function with a source type of S3, an event type of Object Created (all), and the prefix will will match the above INPUT_FOLDER_NAME.

Test by adding video files to the input folder and see that transcoded files populate the output folder. You can troubleshoot errors using Zencoder's job console and the AWS CloudWatch logs for the Lambda function.

About

Example AWS Lambda function for kicking off a Zencoder transcoding job when files are added to an S3 bucket.


Languages

Language:Python 100.0%