This guidance helps users start multiplayer game development quickly by using serverless and fully managed AWS services to host game backends and servers. It includes infrastructure as code automation, as well as deployment scripts to deploy the required resources and supports for Unity and custom C++ engines.
The diagram below presents the architecture you can build using the sample code on GitHub.
Disclaimer: Not for production use
- The game client requests an Amazon Cognito identity and temporary AWS credentials.
- The client signs a matchmaking request to Amazon API Gateway with the temporary credentials. The request includes client latency information to supported AWS Regions.
- API Gateway calls an AWS Lambda function with player identity information.
- The Lambda function gets player skill level from an Amazon DynamoDB table.
- The Lambda function requests matchmaking from GameLift FlexMatch with player skill and latency data.
- GameLift FlexMatch creates a match with multiple players, and an Amazon GameLift queue allocates a session in a GameLift fleet location based on latency data.
- GameLift FlexMatch publishes an event to Amazon SNS on matchmaking success.
- Amazon SNS initiates a subscribed Lambda function for ticket processing.
- The Lambda function stores the ticket result in a DynamoDB table.
- The game client polls for matchmaking success on a defined interval from API Gateway.
- The Lambda function checks matchmaking information from the DynamoDB table and informs the client of a successful match by returning server, IP, port, and player session ID.
- The client connects directly to the server and sends the player session ID. GameLift Server SDK is used to validate the player session.
- Game servers send logs and metrics to Amazon CloudWatch with CloudWatch agent.
The solution is deployed fully with infrastructure as code, and deployment scripts are available for shell and Powershell. You can bring this automation to your own development pipeline to enable fast iteration and consistent deployments. Observability is built in to the solution with process level metrics, logs and dashboards. Extend these mechanisms to your needs, and create alarms in Amazon CloudWatch to inform your on call team on any issues.
The serverless backend is protected with AWS IAM -based authentication for secure validation of the user’s guest identity. Game servers on Amazon GameLift only allow access to the ports used for client-server communication. The backend Lambda functions only have access to the services they need. You can extend the security of the backend by introducing AWS Web Application Firewall, and you can secure your game servers further with more fine-grained traffic filtering for unwanted traffic.
Amazon GameLift hosts game servers across Availability Zones, and all the serverless components are highly available as well. All components are automatically scaling, given the limits for the GameLift Fleet are configured to your scaling needs. To further increase reliability, consider implementing Amazon DynamoDB backups and a cross-region failover plan for the whole infrastructure.
By leveraging serverless technologies, you only provision the exact resources you use. To maximize the performance of the GameLift Fleet, test with multiple instance types, and maximize the amount of game server processes you run on a single instance. For improved performance for the game clients, extend the locations of the multi-region GameLift Fleet to any additional locations as needed.
By utilizing serverless technologies, and an automatically scaling fleet of game servers, you only pay for the resources you use. To further optimize cost, make sure you’re using the game server instance resources effectively by selecting the best performing instance type for your needs, and run as many game servers as you can on a single instance.
By extensively utilizing managed services and dynamic scaling, we minimize the environmental impact of the backend services. A critical component for sustainability is to maximize the usage of the game server instances, as covered in performance and cost pillars. As new compute options become available for Amazon GameLift, make sure you benchmark them against your existing configuration. New hardware is often also more efficient from a sustainability perspective.
The sample code; software libraries; command line tools; proofs of concept; templates; or other related technology (including any of the foregoing that are provided by our personnel) is provided to you as AWS Content under the AWS Customer Agreement, or the relevant written agreement between you and AWS (whichever applies). You should not use this AWS Content in your production accounts, or on production or other critical data. You are responsible for testing, securing, and optimizing the AWS Content, such as sample code, as appropriate for production grade use based on your specific quality control practices and standards. Deploying AWS Content may incur AWS charges for creating or using AWS chargeable resources, such as running Amazon EC2 instances or using Amazon S3 storage.