Build a live streaming chat application using Amazon IVS and Amazon Chime SDK
Building low latency live streaming and implementing chat features are common requests from customers who want an interactive experience. For example, customers who want to build a live streaming app with user-generated content (UGC) look for chat to help enhance interaction between users. In live commerce services, sellers needs to be responsive to product chat inquiries during live streaming. In education, teachers might want to interact with students through Q&A in virtual classrooms.
Amazon IVS helps customers quickly build low latency, interactive live streaming experiences. Based on technology powered by Twitch, Amazon IVS channels are fully managed, low latency live streams, and help enhance the audience experience using a timed metadata API.
The Amazon Chime SDK helps customers build enhanced chat experiences for live streaming. Since the Amazon Chime SDK for messaging feature launch, customers have been able to build asynchronous, scalable, persistent, and interactive chatting experiences and chat features with pay-as-you-go pricing.
In this blog, we will explore how Amazon IVS and Amazon Chime SDK messaging can be used in a live event scenario.
This demo shows you how you can build a compelling live streaming experience with interactivity using Amazon IVS and the Amazon Chime SDK. This demo is intended for education purposes only and is not for use in production.
This demo shows how hosts can quickly spin up IVS channels dynamically and start live streaming. Viewers can watch the live streaming and use scalable chat to interact with other viewers.
Note: Deploying this demo and receiving traffic from the demo created in this post can incur AWS charges
This solution has three main components.
- Amazon IVS is used for creating low latency, global scale of live channels without pre-warming or spin-up time. In addition, timed Metadata ensures that all your viewers receive your metadata payload at the same time in the video stream, regardless of stream latency or geographic location.
- Amazon Chime SDK is used in this demo to allow developers to connect communities of users with scalable and persistent messaging. Using Amazon Chime SDK, users can perform various actions including sending messages, retrieving message history, editing messages, deleting messages, setting retention policies on stored messages, and streaming chat export.
For this walkthrough, you should have the following already:
Deploying the Demo Application
In this section, you will learn how to set up the demo application in your AWS account.
The high-level steps are as follows:
- Using the available AWS CloudFormation template, set up backend resources for chat users using Amazon IVS, Amazon Cognito, and Amazon Chime app instance for chat.
- Deploy the AWS Amplify demo application.
- Explore the features of the demo application.
Step 1. Deploy Backend
In this section, you will deploy backend resources using the AWS CloudFormation template.
- Sign in to the AWS Management Console with your primary account and switch to the us-east-1 (N. Virginia) Region.
- Click on the Launch Stack image.
- Specify Details page, fill out the following information.
– Stack name : Unique Name for CloudFormation Stack
– ChimeRegion : us-east-1
– DemoName : Unique Name for output resources, such as ‘IVSChatDemoApp’
– IVSRegion : us-east-1
Note. Check available region of Amazon IVS and Amazon Chime SDK for messaging prior to deploying CloudFormation.
- Choose Next, and then choose Next on the Configure stack options page.
- On the Review page, check the I acknowledge that AWS CloudFormation might create IAM resources check box. Then click Create.
- Creating the stack generates the following 7 outputs – IvsCreateApiEndpoint, IvsDeleteApiEndpoint, IvsMetaInputApiEndpoint, appInstanceArn, cognitoAppClientId, cognitoIdentityPoolId, cognitoUserPoolId. Note these values for the demo app configuration in the next step.
Step 2. Configure Demo App with the Provisioned Backend
In this section, you bootstrap backend resources into your React demo application with AWS Amplify.
- Sign in to the AWS Management Console
- Go to Cloud9 environment. and Click Open IDE
- Clone the project from GitHub
git clone https://github.com/aws-samples/amazon-ivs-chime-messaging-ugc-demo.git
- Open src/config/apiConfig.js and paste IvsCreateApiEndpoint, IvsDeleteApiEndpoint, IvsMetaInputApiEndpoint value from output of CloudFormation Stack.
- Open src/config/chimeConfig.js and paste the appInstanceArn value from the output of the AWS CloudFormation Stack.Clone the project from GitHub.
Step 3. Install & Configure AWS Amplify
AWS Amplify helps you configure and deploy web applications quickly and efficiently. You can also import and manage backend resources with AWS Amplify.
From the Cloud9 terminal:
- Go to the root folder of source.
- Install the Amplify CLI by running this command :
$ npm install -g @aws-amplify/cli
- Configure the Amplify CLI using this command :
$ amplify configure
- Follow the guided process to completion
- Install dependency and initialize the project using the Amplify CLI command :
$ amplify init
- Follow the guided process to completion.
- Import Amazon Cognito to Amplify project using the Amplify CLI command :
$ amplify import auth
- Follow command as below.
– Choose Cognito User Pool and Identity Pool
– Choose us-east-1
- Configure AWS AppSync with existed schema :
$ amplify add api
- Follow command as below.
– Choose GraphQL.
– Type API Name and Choose Amazon Cognito Pool
– Choose No, I’m Done and type Yes.
– Fill out ./src/config/schema.graphql
- Push Amplify resources to your AWS account and generate AWS AppSync codes in local :
$ amplify push
- Follow command as below.
– Type Yes to continue.
– Type Yes to create GraphQL API.
– Choose Yes and press Enter all selections.
Run the demo application
Now, configuration is complete.
- Run the following command to install dependencies :
$ npm install
- Run the following command to run the demo locally :
$ npm start
- Once the application is started in local, choose Preview > Preview Running Application button in Cloud9 menu bar to run application in browser.
- On the homepage, you have the option to register a user for the demo application. Finish register user, and sign in to navigate further.
- In the main menu, you can list all channels, create a new channel, and list your channels.
- Create a new channel by choosing Create My Channel button. And fill out channel title, and leave others default.
- Once the channel is created, the created channel is listed.
- Enter My Channels > Channel Info, and you will find ingest details of INGEST ENDPOINT and Channel STREAM KEY
- To start live streaming, run the OBS application. And fill out ingest details by choosing settings > Stream tab.
- Select service as Custom.., and Fill out INGEST ENDPOINT to Server, Channel STREAM KEY to Stream Key. Then choose OK.
- Choose Start Streaming. Now your own video channel is ready to air.
Note. For setting up OBS for Amazon IVS, see this blog.
- Go back to the channel menu, and choose the START button. This action allows other users join your channel.
- Now, you can live stream, send heart emojis to viewers, and chat with attendees.
If you no longer want to keep the demo, delete all the AWS resources created so you do not incur further costs.
- Delete all channels in the demo application.
- Delete your CloudFormation Stacks.
- Delete your Cloud9 environment.
In this blog, we showed you how to build an application that uses live streaming and chat. With Amazon Chime SDK’s messaging features and Amazon IVS, customers can create low latency live streaming channels and embed scalable chat into applications. To learn more about how you can use the Amazon Chime SDK for messaging, see the links below.