logo
Build a UGC Live Streaming App with Amazon IVS: Create a Stage for Real-Time Streaming (Lesson 2.4)

Build a UGC Live Streaming App with Amazon IVS: Create a Stage for Real-Time Streaming (Lesson 2.4)

Welcome to Lesson 2.4 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.

TS
Todd Sharp
Amazon Employee
Published Dec 13, 2023

So far in lesson 2, we've looked at how users, channels, and chat rooms are created and associated with one another. We'll close out lesson 2 with a look at how the StreamCat application uses the AWS SDK for JavaScript (v3) to create an Amazon IVS stage for a user to enable real time, multi-host live streams.

To create a Stage for the new User, we invoke the createStage() method of the RealTimeService inside of the /register endpoint handler.
1
2
const createStageResponse: CreateStageCommandOutput =
await RealTimeService.createStage(username);
The createStage() method uses the IvsRealTimeClient from the SDK for JavaScript and sends a CreateStageCommand. The Stage resource requires a name property. For this, we'll use the username property of the User to keep things associated and provide an easy way to retrieve the Stage later on.
1
2
3
4
5
6
7
8
9
public async createStage(name: string): Promise < CreateStageCommandOutput > {
const request: CreateStageCommand = new CreateStageCommand({
name,
tags: {
project: Env.get('DEFAULT_TAG'),
},
});
return await this.ivsRealtimeClient.send(request);
};
The /register endpoint handler collects the channel properties returned in the CreateStageCommandOutput object, constructs a Stage entity, and associates that entity with the User.
1
2
3
4
user.related('stage').create({
name: createStageResponse.stage?.name,
arn: createStageResponse.stage?.arn,
});t
To participate in a real time broadcast via a Stage, each participant will require a participant token. We'll look more at how to generate participant tokens and create the real time broadcasting interface in a subsequent lesson in this course.

At this point, StreamCat has created all of the on-demand resources to allow a user to broadcast a live stream to other viewers. In lesson 3 we'll look at how to provide a user with their unique endpoint and stream key which are necessary to broadcast to their channel from third-party software, as well as how to create several different custom broadcast experiences directly in the StreamCat application itself.


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