File Streaming with AWS Media Services Workshop
Published: 2022-07-17 17:22:41

#AWS #biginner #S3 
In this workshop, you will learn how to process videos for web streaming using AWS services for storage and media transcoding.
This workshop is for developers, operators, or video engineers who want to learn the basics of processing file-based media with AWS Media Services. No prior experience is necessary, but familiarity with the AWS Console, Amazon S3, and AWS Lambda can help.
##Steps
 - We will create an S3(Simple Storage Service) bucket for storing media 
 - We will create an AWS Elemental MediaConvert Job to transcode videos into Apple HTTP Live Streaming (HLS) adaptive bitrate format (ABR) for delivery over the web
 - We will configure the (Identity and Access Management)IAM policies required to grant service access to your content.

##Hint
Costs for running this workshop in your own account, using our provided content (2m long), will be less than 1$.

##Storage
   In this section, you’ll use the console to create an S3 Bucket to store outputs from MediaConvert jobs. To enable access from the test player to your content, you must allow public read access and apply a Cross Origin Resource Sharing (CORS) policy. Typically, an origin server for content would be fronted by a Content Delivery Network like Amazon Cloudfront before going into production, but we will omit this step to keep the workshop shorter in length. A CDN improves performance to end users and reduces load on backend origin infrastructure.
##Create Bucket
1- In the AWS Management Console choose Services then select S3 under Storage.

![S3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bxykhvhq947k4za2a7oz.jpg)
2- Choose +Create Bucket.

![Create Bucket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wmqf3i5i6k0xzsoporqg.jpg)
3- Provide a globally unique name for your bucket such as vod-YOURLASTNAME.

![choose unique name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qyiyhvroiohen62mn8m5.jpg)
4- Select the Region you've chosen to use for this workshop from the dropdown.

![region selection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/usb9otul5kyukk96xvwz.jpg)
5- Choose Create bucket in the lower right of the page.

![create bucket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ecet6w9z5q1y67lqdur4.jpg)
6- From the S3 console select the bucket you just created.

![Select bucket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wuj44z81003j66kq4umj.jpg)
7- Select the Properties tab and click edit on the Static website hosting tile.

![bucket properties](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b1egsjffv9std9ael81i.jpg)

![Static website hosting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r5gr25bos20lbwiqxyh0.jpg)
8- Select Enable to use this bucket to host a static site.

![enable hosting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j7yw5aigxvythie8fe3z.jpg)
9- Enter index.html in the Index document box. Note: S3 requires an index document configuration even though we won’t be using it.

![enter index](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5dl12p6z0vz2om29vex.jpg)
10- Select Save changes.

![save changes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hppl8xii606u8rz0vr7l.jpg)
11- Under the Permissions tab click on CORS configuration and enter the following XML into the CORS configuration editor and click Save. This will allow a browser to request S3 content from any origin.

![permissions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yphfb9835d2vieko275e.jpg)

![edit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vws8jgrf3a9mhx6onmv1.jpg)

![paste xml](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atqtgq3bjcyu5vfhbnme.jpg)

```
[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": [],
        "MaxAgeSeconds": 3000
    }
]
```
##Create an IAM Role
For MediaConvert to read and write from an S3 Bucket and emit status events to CloudWatch, we need to create an Identity and Access Management (IAM) role for MediaConvert to assume. An IAM Role defines a set of permissions to be assumed by a trusted entity, such as a user, service, or application.

1-From the AWS Management Console, click on Services and then 2-select IAM in the Security, Identity & Compliance section.

![iam](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uoldhwn7ddmlid4kamyv.jpg)
2-Select Roles in the left navigation bar and then choose Create role.

![create role](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3pr57ukm7fv495p1r6rk.jpg)
3-Select AWS Service and MediaConvert for the role type, then click on the Next:Permissions button. Note: Selecting a role type automatically creates a trust policy for your role that allows AWS services to assume this role on your behalf. If you were creating this role using the CLI, AWS CloudFormation or another mechanism, you would specify a trust policy directly.

![aws service](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ubxh7b4toxapxtgxskb8.jpg)


![media convert](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0p94e3hrjlzjee61ech2.jpg)


4-Choose Next:Tags


![tags](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fv1zyn7tda3rg6c7r36g.jpg)
5-Choose Next:Review.

![next](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m9o3jtnyyslr2uk2ivqs.jpg)
6-Enter vod-MediaConvertRole for the Role name.

![role name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dqn29pgelwi298h3x6sc.jpg)
7-Choose Create role.

![create role](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pep1j12rd1xk6jw4loc9.jpg)
8-Type vod-MediaConvertRole into the filter box on the Roles page and choose the role you just created.

![select](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dngrnc6lvomn87cs9io6.jpg)
9-Scroll to the top of the page for your new Role and note down the ARN. You will use this in the following modules.

![arn](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xoubapks035f3j4pbe4o.jpg)
##Transcoding
A MediaConvert job reads an input video from S3 and converts the video to output groups that in turn can have multiple outputs. A single media convert job can create multiple versions of the input video in different codecs and packages. For simplicity, in this module, you will create a MediaConvert job that takes a single input video and converts the video into an Apple HLS output group. This is an example of an adaptive bitrate stack that encodes the source into multiple files at different bit rates and divides them into short chunks, usually between 5-10 seconds long. Along with text-based manifest files, the media chunks for each of the encoded streams are hosted via an HTTP server (S3).

1-Open the MediaConvert console for the region you are completing the lab within

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/crjfauxch0gqn7xorgca.jpg)
2-Select Jobs from the side bar menu.

![select job](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hn83jopdshx3garwttl4.jpg)
3-Select Create job to open the Create job page.

![create job](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3v13nfz2qr82k98f1lvx.jpg)
4-Select Input 1 on the Job panel to open the form for Input 1.
5-Enter the file name s3://mediaimmersion/mediaconvert/VANLIFE.m2ts in the box under Input 1.

![name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/407z7ocuulhcmo0n9a4x.jpg)
##Create Job


1-Under Output Groups on the Job panel, select Add.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b9bdqz0dvuy3bwk2oow8.jpg)
2-Check the Apple HLS box then click on Select.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8a4mehl1mc696hcqaz9u.jpg)
3-Make sure Apple HLS is selected in the Job panel in the Output groups section so that Apple HLS form is loaded.

4-Fill in HLS in the Custom group name box with any name, this helps you identify groups easily if you have many in a job or template.
5-In the Destination Browse for bucket name you created from the previous step to and/or construct the output S3 path as follows: s3://vod-YOURLASTNAME/assets/VANLIFE/HLS/

![destination](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i7owppx8f46p9aipc1cx.jpg)
6-Leave the remaining settings as the default.
7-Scroll down to the Outputs panel and click on Add output two times so that there are a total of three outputs.

![3 output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4z53zocj0jyoisil977u.jpg)
8-Select Output 1 from the Output Groups section Jobs panel to go to the Output settings form for Output 1.
9-Select System-Avc_16x9_360p_29_97fps_1200kbps in the preset dropdown.

![360p](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8cwt6fgpuxb113295wlx.jpg)
10-Enter _360 in the Name modifier box to append the resolution to the stream name.

![modifier](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnjzhjssakhyrm5rz93g.jpg)
11-Enter $dt$ in the Segment modifier box to append a datetime to each media segment to uniquely identify the media and prevent accidental overrwrites.

![segment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ni4acw5rcvn9gmjv7akd.jpg)
12-Select Output 2 from the Output Groups section Jobs panel to go to the Output settings form for Output 2.
13-Select System-Avc_16x9_540p_29_97fps_3500kbps in the preset dropdown.

![540p](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/trbuztjj4z307audy0nf.jpg)
14-Enter _540 in the Name modifier box

15-Enter $dt$ in the Segment modifier box.

![segment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a0ouncddyf27sr7wjd78.jpg)
16-Select Output 3 from the Output Groups section Jobs panel to go to the Output settings form for Output 3.

17-Select System-Avc_16x9_720p_29_97fps_5000kbps in the preset dropdown.

18-Enter _720 in the Name modifier box
19-Enter $dt$ in the Segment modifier box.

![segment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ra9v8j4fzjmh75jef5i.jpg)
20-Select AWS Integration from the Job settings section of the Job panel to open the Job settings form.

![integration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xl68l2czdaqui7regos5.jpg)
21-Select the role you created in the previous section of this lab from the Service role dropdown.

![select role](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ffntj8ua7cwxjdxpw0bt.jpg)
22-Scroll to the bottom of the page and select Create

![create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nwqs73dn06476anyfyq4.jpg)
23-Wait for the job to complete. Monitor the status of the job by refreshing the Job details page using the refresh button.
![refresh](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gvpiw601qjguabl4ph3u.jpg)
##Playback
To play the videos, you must make the manifest and segment files public. In order to do so, you need to remove the restrictions imposed by S3 that prevent accidental public objects, then make the MediaConvert output objects public.

1-Navigate to your Media Bucket and select Permissions, then Public access settings and edit.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v5z7qhin9qqsxxbuwdt9.jpg)
2-Uncheck the “Block new public ACLs…” and “Remove public access…” options as shown below

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7lmmqar1e6jh0vrhvj59.jpg)
3-Save and type ‘confirm’
4-Now that you have permissions to make our object public, navigate to the root of your Media Bucket by selecting Overview.
5-Check the box next to the ‘assets’ folder, select Actions, and finally Make public
6-Get the Object URL for the manifest file located in /assets/VANLIFE/HLS/ it should look like:
https://s3.amazonaws.com/<MediaBucket>/assets/VANLIFE/HLS/VANLIFE.m3u8

7-Play the stream using the Safari browser by clicking on the Link for the object or use the JW Player Stream Tester .

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3zjcygli48z2bs6hnhrr.jpg)
Congratulations! You have successfully created an adaptive bitrate video-on-demand stream using AWS Elemental MediaConvert and used S3 as an origin server.