Transcoding Video with S3 and Elastic Transcoder

Hands-On Lab

 

Photo of Mark Richman

Mark Richman

AWS Training Architect II in Content

Length

01:00:00

Difficulty

Intermediate

In this hands-on AWS lab, we'll learn how to convert video files to different formats using Lambda, S3, and Amazon Elastic Transcoder. Elastic Transcoder is a media service designed to be a highly scalable, easy-to-use, and cost-effective way to convert (or "transcode") media files from their source format into versions that will play back on devices like smartphones, tablets, and PCs. In this lab, you will upload 4K Ultra HD sample videos to an S3 bucket and configure an Elastic Transcoder pipeline to automatically convert them to different formats. We'll set all this up with our own custom Lambda function — written in Python — using the Boto3 SDK. - Download the sample 4K videos here and here. - Download the Lambda execution role IAM policy here. - Download the Lambda function source code here.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Transcoding Video with S3 and Elastic Transcoder

Introduction

In this hands-on AWS lab, we'll learn how to convert video files to different formats using Lambda, S3, and Amazon Elastic Transcoder.

Elastic Transcoder is a media service designed to be a highly scalable, easy-to-use, and cost-effective way to convert (or "transcode") media files from their source format into versions that will play back on devices like smartphones, tablets, and PCs.

In this lab, we will upload 4K Ultra HD sample videos to an S3 bucket and configure an Elastic Transcoder pipeline to automatically convert them to different formats. We'll set all this up with our own custom Lambda function — written in Python — using the Boto3 SDK.

  • Download the sample 4K videos here and here.
  • Download the Lambda execution role IAM policy here.
  • Download the Lambda function source code here.

Log in to the AWS Management Console with the credentials provided on the lab instructions page. Make sure you are using the us-east-1 (N. Virginia) region.

Subscribe to an SNS Topic

  1. In the AWS Management Console, navigate to the SNS service.
  2. Click Topics in the left sidebar.
  3. Select the Transcoder topic.
  4. Click Actions, then Subscribe to topic.
  5. In the Protocol dropdown box, select Email.
  6. In the Endpoint box, type an email address you can use to receive the notification.
  7. Click Create subscription.
  8. Go to your email application and open the message from AWS Notifications.
  9. Click the link to confirm your subscription.
  10. Go back to your SNS browser tab, and open the Transcoder topic to verify that the subscription is confirmed.

Create an Elastic Transcoder Pipeline

  1. In the AWS Management Console, navigate to the Elastic Transcoder service.
  2. Click Create a new Pipeline.
  3. Under Create New Pipeline, configure the following settings:
    • Pipeline Name: MyPipeline (or any name you like)
    • Input Bucket: (Select the bucket with source in its name.)
    • IAM Role: Create console default role
  4. Under Configuration for Amazon S3 Bucket for Transcoded Files and Playlists, configure the following settings:
    • Bucket: (Select the bucket with transcoded in its name.)
    • Storage Class: Standard
  5. Under Configuration for Amazon S3 Bucket for Thumbnails, configure the following settings:
    • Bucket: (Select the bucket with thumbnails in its name.)
    • Storage Class: Standard
  6. Expand the Notifications menu.
  7. Select Use an existing SNS topic for all of the events.
  8. For Select a Topic, choose Transcoder from the dropdown for all of the events.
  9. Click Create Pipeline.
  10. Note the Pipeline ID. (This is available in the pipeline details and is a different value than the pipeline name.)

Create a Lambda Function

  1. In the AWS Management Console, navigate to the Lambda service.
  2. Click Create a function.
  3. Choose the Author from scratch option, and configure the following settings:
    • Name: TranscodeVideo (or any name you like)
    • Runtime: Python 3.7
    • Role: Create a custom role
  4. In the Role Summary screen, click View Policy Document.
  5. Click Edit.
  6. In a new browser tab, open this file, and copy the contents to your clipboard.
  7. Paste the text into the IAM policy document editor, replacing the text that was there before.
  8. Click Allow.
  9. Go back to your Lambda Management Console browser tab, and click Create function.
  10. Scroll down the list of triggers on the left side of the screen, and select S3.
  11. Scroll down the page to the Configure triggers section, and configure the following settings:
    • Bucket: (Select the bucket with source in its name.)
    • Event type: All object create events
  12. Make sure the box next to Enable trigger is checked, then click Add.
  13. Click the function name (TranscodeVideo) at the top of the page.
  14. Scroll down the page to the function editor, and remove the default text.
  15. In a new browser tab, open this file and copy the contents to your clipboard.
  16. Go back to the Lambda Management Console, and paste the function body source code into the code editor.
  17. Switch back to your Elastic Transcoder tab, and click the magnifying glass icon to view the details for our pipeline.
  18. Copy the Pipeline ID to your clipboard, and switch back to your Lambda Management Console browser tab.
  19. Scroll down to the Environment variables section, and set the following variable:
    • Key: PIPELINE_ID | Value: (Paste the pipeline ID from the pipeline summary page)
  20. Click Save.

Upload Video for Transcoding

  1. In the AWS Management Console, navigate to the S3 service.
  2. Open the S3 bucket with source in its name.
  3. Click Upload.
  4. Click Add files.
  5. Select one of the 4K sample video files you downloaded to your local machine.
  6. Click Upload.
  7. Open your email application, and check for an email notification from Elastic Transcoder.
  8. Go back to the S3 Management Console, and open the S3 bucket with transcoded in its name.
  9. Verify that the 1080p and 720p versions of your uploaded video are present.
  10. Select one of the transcoded versions of the uploaded video, and verify that it is in the correct format.
  11. Go back to the S3 home page, and select the S3 bucket with thumbnails in its name.
  12. Select the .png image that was created, and click Open to verify that the thumbnail was successfully created.

Conclusion

Congratulations, you've successfully completed this lab!