logo
Build a UGC Live Streaming App with Amazon IVS: Creating an Amazon IVS Chat Room (Lesson 2.3)

Build a UGC Live Streaming App with Amazon IVS: Creating an Amazon IVS Chat Room (Lesson 2.3)

Welcome to Lesson 2.3 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

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

To create a chat room for the new User, we invoke the createChatRoom() method of the ChatRoomService inside of the /register endpoint handler.
1
2
const createChatRoomResponse: CreateRoomCommandOutput =
await ChatRoomService.createChatRoom(username);
The createChatRoom() method uses the IvschatClient from the SDK for JavaScript and sends a CreateRoomCommand. The CreateRoomCommandInput object requires a name property for the chat room. For this, we use the username property of the User entity, to keep an association between the resources for each user. Each ChatRoom references a single, shared messageReviewHandler AWS Lambda function as well as a shared and pre-built chat logging configuration within the loggingConfigurationIdentifiers array. Refer to lesson 1.4 to learn more about these pre-built resources.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public async createChatRoom(name: string): Promise < CreateRoomCommandOutput > {
const request: CreateRoomCommand = new CreateRoomCommand({
name,
messageReviewHandler: {
uri: Env.get('MODERATE_CHAT_FUNCTION_ARN'),
fallbackResult: 'ALLOW',
},
loggingConfigurationIdentifiers: [
Env.get('CHAT_LOGGING_CONFIGURATION_ARN')
],
tags: {
project: Env.get('DEFAULT_TAG'),
},
});
return await this.ivsChatClient.send(request);
};
The /register endpoint handler collects the channel properties returned in the CreateRoomCommandOutput object, constructs a ChatRoom entity, and associates that entity with the User.
1
2
3
4
5
user.related('chatRoom').create({
name: createChatRoomResponse.name,
arn: createChatRoomResponse.arn,
endpoint: `wss://edge.ivschat.${Env.get('AWS_REGION')}.amazonaws.com`,
});

In this lesson, we learned how the StreamCat application creates an Amazon IVS chat room for each user and associates that chat room with the user. Later on, we'll see how to add live chat to the user's channel page to allow the broadcaster and viewers to interact with one another.


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