An easy-to-deploy web application example for Amazon GameLift Streams that enables browser-based game streaming with URL sharing capabilities.
Make sure you have the following prerequisites before continuing to the next step:
- An AWS account with proper credentials for programmatic access. For detailed instructions, refer to Setting up Amazon GameLift Streams in the Amazon GameLift Streams Developer Guide.
- An Amazon GameLift Streams-supported web browser. Refer to Supported browsers and input in the Amazon GameLift Streams Developer Guide.
- Node.js 16 or newer. Download this from the Node.js downloads page.
Before using either component, you will need to obtain the latest Amazon GameLift Streams Web SDK and drop it into the project files.
- Clone this repository to your computer.
- Download the latest Web SDK bundle from the Amazon GameLift Streams Getting Started product page.
- Unzip the bundle.
- Copy the
gameliftstreams-x.x.x.mjs
andgameliftstreams-x.x.x.js
files into theserver/public
folder of this project (next to the other source files likeindex.html
).
You can choose to set up either or both of the following components, based on your needs:
Windows:
- Run
install_server.bat
Linux/OSX: Open Terminal and enter these commands:
chmod +x install_server.sh
./install_server.sh
If you have any issues running the install script, try:
dos2unix install_server.sh
To deploy this AWS Cloud Development Kit (CDK) stack, you'll need some additional toolsthe following permissions/configurations in your AWS account:
-
Base AWS Identity and Access Management (IAM) Permissions:
- Amazon CloudFormation full access (
cloudformation:*
) - AWS IAM role creation permissions (
iam:CreateRole
,iam:PutRolePolicy
, etc.) - AWS Lambda management permissions (
lambda:*
) - Amazon API Gateway management permissions (
apigateway:*
) - Amazon GameLift Streams permissions (
gameliftstreams:*
) - Amazon CloudWatch Logs permissions (for AWS Lambda logging)
- Amazon CloudFormation full access (
-
AWS CDK Bootstrap: Your account/region needs to be bootstrapped for AWS CDK. Please see information about AWS CDK Bootstrap here: https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html
-
AWS CLI Configuration: Ensure your AWS CLI is configured with appropriate credentials. Please see information on how the AWS CLI is configured here: https://docs.aws.amazon.com/cli/v1/userguide/cli-chap-configure.html
-
Deployment Environment Variables: When deploying the AWS CDK stack, you can use the standard
CDK_DEFAULT_REGION
environment variable to specify the AWS region to use. This is considered a better practice than hardcoding the region in the code, as it makes the deployment more flexible and reusable. For example: Windows:set CDK_DEFAULT_REGION=us-west-2 deploy_cdk.bat
Linux/OSX:
export CDK_DEFAULT_REGION=us-west-2 ./deploy_cdk.sh
Deploy and Install:
-
On the Amazon GameLift Streams console Dashboard, select Stream groups.
-
Select the stream group you wish to stream from and locate its 'Stream group ID'. You will need it to run the deployment script. Make sure the application(s) you wish to stream are associated with it.
-
Deploy the AWS CDK stack.
Windows: Open Terminal and use command:
Example:
deploy_cdk.bat sg-000000000
# use your stream group ID in place of 'sg-000000000'
Linux/OSX: Open Terminal and use commands:
chmod +x deploy_cdk.sh
./deploy_cdk.sh sg-000000000
If you have any issues running the script, try:
dos2unix deploy_cdk.sh
-
After deployment is complete, your shareable stream URL will be output in this format:
https://[API-ID].execute-api.[REGION].amazonaws.com/prod/?userId={Player Name}&applicationId={Your-Application ID}&location={Your AWS Region}
-
Automated Setup Scripts - Check and install required dependencies:
- Node.js
- AWS CLI
- AWS CDK
- AWS credentials configuration (for CDK deployment)
-
Real-time Client Side WebRTC Metrics
-
WebRTC performance monitoring
-
Movable metric widgets
-
Full-screen compatibility
-
CSV export capability
More about WebRTC Metrics here: https://www.w3.org/TR/webrtc-stats
-
-
Mobile Support
- Automatic mobile device detection
- Customizable virtual controller
- Touch controls
- Orientation settings
Typical use should be within AWS CloudFormation free tier, see: Provision Infrastructure As Code – AWS CloudFormation Pricing – Amazon Web Services
AWS SDK Related:
- @aws-sdk/client-bedrock-runtime
- @aws-sdk/client-cloudwatch
- aws-sdk
Third-party Packages:
- chart.js
- cors
- express
- node-fetch
- serverless-http
-
Delete the CloudFormation Stacks:
- Login to the AWS Management Console.
- Navigate to the AWS CloudFormation service.
- In the AWS CloudFormation dashboard, locate the stack named
gameliftstreams-share-url-cdk
and select it. - Click the "Delete" button to delete this stack.
- Next, locate the stack named
CDKToolkit
and repeat the process to delete this stack. - It's important to delete the stacks in this order, as the
CDKToolkit
stack may have dependencies on thegameliftstreams-share-url-cdk
stack.
-
Delete the Amazon S3 Bucket:
- In the AWS Management Console, navigate to the Amazon S3 service.
- Locate the Amazon S3 bucket that was created.
- First, empty the contents of the bucket. You can do this by either:
- Manually deleting all objects in the bucket.
- Using the "Empty" button in the Amazon S3 console to empty the bucket.
- Once the bucket is empty, you can then delete the bucket itself.
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. Please See the LICENSE file.