Business Productivity
How to Enable Client-Side Recording Using the HAQM Chime SDK
Builders who integrate real-time communications in their own web applications with the HAQM Chime SDK often ask how to enable client-side recording of audio calling, video calling, and screen sharing sessions. In this blog post, we demonstrate how you can deploy web-based recording service into your AWS account and record an HAQM Chime SDK session.
Solution overview
You begin this walkthrough by creating a AWS Cloud9 environment in your AWS account and deploying a docker container image containing the demo recording application into the HAQM Elastic Container Registry (HAQM ECR). AWS Cloud9 environments come pre-installed with AWS Command Line Interface (AWS CLI), AWS Serverless Application Model (AWS SAM), Docker, Git, and Node.js, which are necessary to deploy the demo recording application.
Next, you deploy an AWS CloudFormation stack that creates several resources such as an HAQM Elastic Container Service (HAQM ECS) cluster with an auto-scaling group, AWS Lambda, and a recording endpoint in HAQM API Gateway to start and stop recording. At this point, you have a generic website recording service that records audio and video for any web page that can be visited by a URL. The recording service can be scaled on-demand using HAQM ECS. For the best performance, you can deploy the recording service in the media region of the Chime SDK meetings you plan to record.
Once invoked, the recording service starts a recording task within the HAQM ECS cluster whose ARN is returned in the API response. This ARN is required to stop the recording at any time. The recording application joins the meeting as a participant, captures the web page rendered in Firefox using FFMpeg, xvfb, and PulseAudio, transcodes it to an Mpeg-4 video file format, and uploads the resulting media file via a multi-part upload to an HAQM S3 bucket.
The diagram below depicts this flow:
Demo recording application walkthrough
Prerequisites
To deploy and explore the recording service, you should have the following prerequisites:
- An AWS account
- Postman application for invoking the recording APIs in HAQM API Gateway
- An AWS Identity and Access Management (IAM) Administrator policy to set up the demo.
Note: Deploying the recording demo application can incur charges on your AWS account.
Key steps
Here is an outline of the key steps involved in deploying and using the application.
- Create an AWS Cloud9 environment
- Create an HAQM ECR repository, build, and upload the docker image
- Set up the recording service
- Start an HAQM Chime SDK meeting with the HAQM Chime SDK demo and join with multiple participants
- Start the meeting recording
- Stop the recording and view the recording artifact
- Cleanup
Create an AWS Cloud9 environment
- Log in with your AWS credentials and go to the AWS Cloud9 Console. If you have previously set up a AWS Cloud9 environment in your account you can use it and skip this step entirely.
- Press the Create environment button or go here.
- For the Name enter <unique environment name> and press the Next step button.
- For Environment Settings use the defaults and press the Next step button.
- Review the Environment name and settings and press the Create environment button.
- You can optionally use your own HAQM EC2 instance if you have configured.
Wait for the environment to start. Once completed, a welcome message from AWS Cloud9 along will a bash shell will be displayed.
Create an HAQM ECR repository, build, and push the docker image
- In the bash shell of the AWS Cloud9 instance, run the below command to create a repository in HAQM ECR:
aws ecr create-repository --repository-name repository-name
This returns a JSON response similar to the following:
{ "repository": {"repositoryArn":"arn:aws:ecr:us-east-1:<accountId>:repository/<repository-name>","registryId": "<accountId>","repositoryName": "<repository-name>", "repositoryUri": "<accountId>.dkr.ecr.us-east-1.amazonaws.com/<repository-name>","createdAt": 1585247726,"imageTagMutability": "MUTABLE","imageScanningConfiguration": {"scanOnPush": false}}}
2. Execute the following commands to clone the recording demo in the AWS Cloud9 instance.
git clone http://github.com/aws-samples/amazon-chime-sdk-recording-demo.git
cd amazon-chime-sdk-recording-demo
3. Once done, execute the following command with the value of repositoryUri from step 1 to build and upload the docker image into HAQM ECR.
make ECR_REPO_URI=<repositoryUri>
Navigate to HAQM ECR console to verify that the image exists.
Set up the recording service
- Execute the following command to deploy the AWS CloudFormation stack shipped with the demo. This sets up the recording service along with IAM roles and networking resources such as HAQM Virtual Private Cloud (HAQM VPC), subnets, security groups, and an auto-scaling group required for the HAQM ECS Cluster.
node ./deploy.js -b <my-bucket> -s <my-stack> -i <my-docker-image> -r <region>
This step can take several minutes to complete. Once done, the Recording Service URL is printed in the output.
Start an HAQM Chime SDK meeting with the HAQM Chime SDK meeting demo and join with multiple participants
- You can download the HAQM Chime SDK Meeting demo by executing the following:
cd ../
git clone http://github.com/aws/amazon-chime-sdk-js
cd demos/serverless
2. Once done, deploy this demo by:
node ./deploy.js -r us-east-1 -b <my-bucket> -s <my-stack-name> -a meeting
The bucket name should be lower case and globally unique. The deploy script creates an AWS CloudFormation stack along with AWS Lambda and API Gateway resources required to use the demo. After the script finishes, it outputs a URL that can be opened in a browser.
3. Open the demo using the link which was obtained in the previous step and create a meeting with the text box provided. Once the permissions to use the microphone and speakers are granted, you will join an HAQM Chime SDK meeting.
4. Copy the URL obtained in the previous step in multiple tabs in any web browser supported by HAQM Chime SDK to simulate several participants joining the meeting. Optionally enable video or content sharing modalities for each participant in addition to audio.
Start the meeting recording
There are multiple ways for invoking a REST API in HAQM API Gateway. In this example, we use Postman.
- Follow the steps highlighted in this developer guide to install Postman.
- You need to select “AWS Signature” in the Postman application and add your AccessKey, SecretKey & AWS Region in the Authorization tab.
Entering authentication with the Postman Application
3. Start recording by passing the recordingAction as “start” and a meetingURL to the recording service as query parameters in the POST request to the recording service. The URL must be URL encoded. This is shown in the picture below.
Initiating recording with the Postman Application
The entire web page is captured by FFmpeg at 720p (1280 X 720) fidelity and automatically transcoded and uploaded to HAQM S3. The file created in S3 remains hidden until the capture is complete. The HAQM Chime SDK demo application has been modified to suppress prompts for input device permissions and display customized UI for the recording bot.
Recording Application Joining the Meeting
It takes up to 30 seconds for the meeting bot to join the meeting for the first time. Subsequently, the bot takes under 5 seconds to join.
Stop the recording and view the recording artifact
- To stop the recording, you need to pass the ARN that was received in the API response to start the recording along with the recordingAction as “stop”.
Stopping recording with the Postman Application
2. Once the recording stops open the AWS Console and navigate to HAQM S3. The recording is saved in the bucket chime-meeting-sdk-<aws-account-id>-<region>-recording-artifacts with the following format: YYYY/MM/DD/HH/<ISO8601 time when meeting started>.mp4. You can now play or edit this recording, as necessary.
Cleanup
To avoid incurring any unintended charges as a result of deploying the recording demo application, it is important to delete any resources in your AWS account that you are not using such as the AWS CloudFormation stacks, AWS Cloud9 environment, and HAQM S3 recordings. Deleting these should automatically delete the resources used in this demo recording service.
Next Steps & Resources
In this blog, we have shown how your HAQM Chime SDK meeting can be recorded. It works by installing a docker image that runs in an HAQM ECS container and creates a meeting bot that joins a meeting, records the entire web page along with the media, transcodes it as an MPEG-4 file, and stores the file in an HAQM S3 bucket.
As an application builder you can customize the web page being recorded for any layout, control whether the recording participant is seen on the roster or not, and control which region the recording artifacts is stored in for compliance reasons.
To learn more about how you can use the HAQM Chime SDK, visit the HAQM Chime SDK web page. To start building, visit the HAQM Chime SDK GitHub repository for sample code and downloads. You can also refer to service documentation using the following links:.
- Building a Meeting Application using the HAQM Chime SDK
- HAQM Chime API Reference Documentation
- HAQM Chime Developer Guide
- Getting started with HAQM Chime SDK for JavaScript
- Building a Virtual Classroom Application using the HAQM Chime SDK
- Who can join AWS Educate
- Powering your HAQM ECS Cluster with HAQM EC2 Spot Instances