paint-brush
Live Stream in the Cloud with Amazon IVS: Part 1by@amazonivs
12,826 reads
12,826 reads

Live Stream in the Cloud with Amazon IVS: Part 1

Too Long; Didn't Read

Amazon Interactive Video Service (or Amazon IVS) is the service that powers Twitch. You can use it to power your own interactive live video streaming applications. At its core, Amazon allows you to: create a channel, create a playback interface, broadcast (or “stream), and create playback interfaces. In 2021, over [1.3 trillion (with a T) minutes were streamed on Twitch. That’s a lot of live-streaming traffic. Right now, there are about 2.5 million people watching a live stream on [Twitch.tv]. By the end, 31 million people will have tuned in.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Live Stream in the Cloud with Amazon IVS: Part 1
Amazon Interactive Video Service (IVS)  HackerNoon profile picture

Getting Started with Amazon Interactive Video Service (4-Part Series)

It’s becoming impossible to ignore live streaming. There are tons of studies that illustrate its popularity and continued growth, but forget the numbers for just a second and consider how many of us consume news media, and entertainment, and even how some of us workout. We’re becoming more dependent on the internet to deliver us what we want and need, and we want it fast, reliably, and on demand.


I won’t spend a bunch of time trying to convince you that live streaming solves all of your problems. If you’re reading this, then you probably already have a good idea that live streaming is a great fit for your application. If not, you should still keep reading - trust me, even the smallest use cases can benefit from what we’re going to explore.


But - and I can tell you this from experience - it’s really hard to build a quality live-streaming experience from the ground up. It sounds easy enough. If you wanted to, you could spin up a compute instance, update the OS, install some open-source media server software, open the firewall and virtual network ports and get a stream up and running in a day. But what happens when someone connects to your stream from the other side of the world? What about when your stream gets really popular and a few thousand people want to view it? Are you prepared to manage auto scalers, load balancers, and OS updates/patching/maintenance? Yeah, me neither.


Really smart people have already solved this problem. Right now, there are about 2.5 million people watching a live stream on Twitch. By the end of the day, 31 million people will have tuned in at some point. In 2021, over 1.3 trillion (with a T) minutes have been streamed on Twitch. That’s a lot of live-streaming traffic. Twitch didn’t build its product overnight. Enter Amazon Interactive Video Service (or Amazon IVS). Amazon IVS is the service that powers Twitch. And you can use it to power your own interactive live video streaming applications. So, how does it work? There are several different options for broadcasting and playback, but at its core, Amazon IVS allows you to:


  • Create a channel
  • Create a playback interface
  • Broadcast (stream)


There are different ways to create channels (console, CLI, SDK) and create playback interfaces (web, native). There are also different ways to broadcast (or “stream”) to your channels (desktop software, mobile apps, web broadcast). I’ll show you how all of these work in future posts, but today let’s get the basics out of the way by just creating a channel and streaming to it. If you’ve never live streamed before, the quickest way to get started from your laptop/desktop is to install something like Streamlabs Desktop or OBS. Another quick and easy way to stream is to do it directly from the command line with FFMPEG, but this method will not include some of the nicer features of other options (like easily streaming a desktop window or application and adding fun transitions to your scenes). Still, it’s an easy way to test your channel. We’ll look at how to use FFMPEG in a future post.

Creating an AWS Account

First things first - you’ll need an AWS account to get started. Don’t have one yet? Sign-up is easy, and new accounts can take advantage of the AWS Free Tier for Amazon IVS (5 hours of basic input and 100 hours of SD video output each month - plus more). Trying Amazon IVS can cost you nothing, so sign up and follow along with this post to create your own channel (and stay tuned for future posts where we dig into much more)!


Wondering what it’ll cost to run Amazon IVS in your production application? Check out the Amazon IVS Cost Estimator!

Creating a Channel

Got that new account created? Great, let’s create a channel! Head over to the Amazon IVS Management Console. The first thing to do here is select a region for control and creation of your streams:


Don’t worry – video ingestion and delivery are available around the globe over a separate managed network of infrastructure that is optimized for live video. Now that we’ve selected a region on the Amazon IVS Management Console home page, click on Create Channel.

On the Create Channel page, the first thing we’ll need to do is give our channel a name:

Next, under Channel configuration, select Custom configuration. If you created a new account, the AWS Free Tier applies to Basic channel types, so we'll select that. Leave Ultra-low latency selected.

Amazon IVS supports playback authorization with authentication tokens. We won’t dig into this today, so leave Playback authorization disabled.

If you want to capture all of your live streams for future playback, select Auto record to S3. This can be super handy if you are streaming something like a webinar or conference session and would like to offer on-demand playback later on. For now, let’s leave this disabled.

If you’d like to tag your channel, you can enter them in the next section. Once you’re done, click Create channel.

Channel Details

After we create our channel, we’re redirected to the Channel details page. At the top of this page, there is some helpful text and links to the Amazon IVS docs.

Scroll down a bit to view a summary of the options that we selected for our channel.

If we plan to do any work with this channel via an SDK or CLI, we’ll need to take note of the channel ARN.

Below the channel summary, we can see a panel titled Live stream

Expanding this panel (by clicking on the panel header) will reveal a built-in video player that we can use to view the current video on our stream. Since we’re not broadcasting yet, the player will be initially offline.

Below the live stream, player is a panel dedicated to Timed metadata.

Timed metadata is an exceptional feature that lets us inject data payloads into our video stream that we can retrieve on the client side at the exact point in time that we broadcast it to the stream. This is super handy and can enable some pretty interactive content. Again, we’ll save this topic for a future post!

Below the timed metadata panel is the Stream configuration panel, which contains our Stream key and Ingest server.

Note both values, as we’ll use them in just a bit to stream to our channel via rtmps with OBS and FFMPEG. We can also stream via the Web Broadcast SDK (using the endpoint specified under Other ingest options). Yeah, that’s also another post...

Scrolling down more will reveal our custom Playback URL in the Playback configuration panel.

We’ll use this in a future post when we take a look at the various options for stream playback. We won’t need this value today, since we’re just going to test our stream in the Amazon IVS console.

Creating a Channel via the AWS CLI

If you prefer to use the AWS CLI to manage your AWS resources, you can create a channel with the same configuration that we used above via the following command:

$ aws \
    ivs \
    create-channel \
    --name my-first-ivs-channel \
    --type BASIC \
    --latency-mode LOW \
    --no-authorized


When creating your channel via the CLI, all the information that is displayed in the stream detail information (the channel ARN, stream key, etc.) get returned in a JSON object.

{
    “channel”: {
        “arn”: “arn:aws:ivs:us-east-1:[redacted]:channel/[redacted]”,
        “authorized”: false,
        “ingestEndpoint”: “[redacted].global-contribute.live-video.net”,
        “latencyMode”: “LOW”,
        “name”: “my-first-ivs-channel”,
        “playbackUrl”: “https://[redacted].us-east-1.playback.live-video.net/api/video/v1/us-east-[redacted].channel.[redacted].m3u8”,
        “recordingConfigurationArn”: “”,
        “tags”: {},
        “type”: “BASIC”
    },
    “streamKey”: {
        “arn”: “arn:aws:ivs:us-east-1:[redacted]:stream-key/[redacted]”,
        “channelArn”: “arn:aws:ivs:us-east-1:[redacted]:channel/[redacted]”,
        “tags”: {},
        “value”: “sk_us-east-[redacted]”
    }
}

We’re Live in 3, 2, 1...

We’re ready to go live! Make sure that you have your stream key and ingest endpoint handy and fire up OBS. In OBS, select Profile, then New, and name your profile my-first-ivs-channel. In the Auto-Configuration Wizard, choose to Optimize for streaming, recording is secondary, and click Next.

In the next step, accept the default values.

Next, choose Custom in the Service input dropdown, enter your Amazon IVS ingest endpoint as the Server and paste our Stream Key in the input box. Leave Estimate bitrate and bandwidth checked and click Next.

OBS will now run some tests to estimate the ideal settings for this channel.

Once the test is complete, OBS will output the results. We’ll accept the recommendations here (note that since this is a Basic channel, OBS properly detected the output resolution of 480p).

Click Apply Settings and in the main OBS window, select the first Scene under Scenes. In Sources, click on the plus icon and select Video Capture Device. Choose your webcam and add it as a Source. You should now see a preview of your stream in OBS:

The only thing standing between us and our live stream is clicking on the Start Streaming button (shown in the screenshot above). So, what are we waiting for, let’s click it! Once we’ve started streaming, we can head back to the Amazon IVS Management Console and reload our stream details page and expand the live viewer to see our live stream.

And that’s it! We’re live streaming to the internet!

Summary

In this post, we created our very first channel with Amazon IVS and started our very first live stream. As I mentioned several times, there is so much more to IVS. Stay tuned here for more posts soon where we will look at the various options for broadcasting, playback, and adding interactive features (like live chat, and more)!