logo
Menu
Build a UGC Live Streaming App with Amazon IVS: Creating an Amazon IVS Channel (Lesson 2.2)

Build a UGC Live Streaming App with Amazon IVS: Creating an Amazon IVS Channel (Lesson 2.2)

Welcome to Lesson 2.2 in this series where we're looking at building a web based user-generated content live streaming application with Amazon IVS. This entire series is available in video format on the AWS Developers YouTube channel and all of the code related to the sample application used in this series can be viewed on GitHub. Refer to the links at the end of the post for more information.

Todd Sharp
Amazon Employee
Published Dec 13, 2023

Intro

In lesson 2.1, we saw how StreamCat persists a user to the database in the handler for the /register endpoint within the application. In this lesson, we'll see how the StreamCat application uses the AWS SDK for JavaScript (v3) to create an Amazon IVS channel for a user.

Creating a Channel

To create a channel for the new User, we invoke the createChannel() method of the ChannelService inside of the /register endpoint handler.
1
2
const createChannelResponse: CreateChannelCommandOutput =
await ChannelService.createChannel(username);
The createChannel() method uses the IvsClient from the SDK for JavaScript and sends a CreateChannelCommand. The CreateChannelCommandInput object requires a name, which is the same as the username property of the User object. The input object also contains a type property which defines the type of input and output for the channel. More on this property in just a bit. The recordingConfigurationArn is a reference to a pre-built and shared recording configuration resource and is retrieved from the application's environment variables (refer to lesson 1.4 to learn more about pre-built resources).
1
2
3
4
5
6
7
8
9
10
11
12
public async createChannel(name: string): Promise < CreateChannelCommandOutput > {
const request: CreateChannelCommand = new CreateChannelCommand({
name,
type: 'BASIC',
latencyMode: 'LOW',
tags: {
project: Env.get('DEFAULT_TAG'),
},
recordingConfigurationArn: Env.get('RECORDING_CONFIGURATION_ARN'),
});
return await this.ivsClient.send(request);
};
Note: In StreamCat, new users are given a 'BASIC' channel. This means that their video is transmuxed which means that Amazon IVS delivers the original input quality to viewers. The viewer’s video-quality choice is limited to the original input. Input resolution can be up to 1080p and bitrate can be up to 1.5 Mbps for 480p and up to 3.5 Mbps for resolutions between 480p and 1080p. Original audio is passed through. Later, when a channel reaches a certain threshold, we can modify this channel type for more prolific content creators. See this document to learn more about the differences between different channel types in Amazon IVS.
The /register endpoint handler collects the channel properties returned in the CreateChannelCommandOutput object, constructs a Channel entity, and associates that entity with the User.
1
2
3
4
5
6
7
user.related('channel').create({
name: createChannelResponse.channel?.name,
playbackUrl: createChannelResponse.channel?.playbackUrl,
arn: createChannelResponse.channel?.arn,
ingestEndpoint: createChannelResponse.channel?.ingestEndpoint,
streamKey: createChannelResponse.streamKey?.value,
});

Summary

In this lesson, we learned how the StreamCat application creates an Amazon IVS channel for each user and associates that channel with the user. With this information, we'll be able to provide the user with their dedicated credentials to broadcast to their own channel from third-party software, as well as create a custom broadcast experience for users in the StreamCat application. We'll learn more about broadcasting in lesson 3 of this course. In the next lesson, we'll learn how to create a chat room for each user.

Links

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments