
I Built a Lobby Feature Using Amazon GameLift Servers and AppSync Events
This page has been translated by machine translation. View original
Hello, I'm Sora from the Game Solutions Department.
This time, I built a lobby feature that runs Amazon GameLift Servers game sessions as lobbies and delivers the lobby list and notifications addressed to individual players through AWS AppSync Events, so I'll write up the details in this article.
The App I Built
The app I built this time looks like this.
When you pick a lobby from the list and enter it, you see the players in the lobby and a chat.

The list shows the status of each lobby (open, dormant, etc.) and its player count.
Updates to the list are delivered via AppSync Events.

Inside a lobby, the player list appears on the left and the chat on the right.
When you change your name with the pencil icon at the top right, the game server saves it to DynamoDB and sends it to everyone in the lobby.
In the image, I changed my own name to "player" and the bot's name to "Bot 1".
The game server replaces "idiot" (written in Japanese as "ばか") sent in chat with ** before distributing it.
Chat messages are delivered only to people in the same lobby.
Even if you leave and re-enter, or enter a different lobby, you join with the name you changed.
Architecture
The architecture I built this time is as follows.

Instead of starting and ending a game session for each match, I keep game sessions running for a long time and use them as lobbies that players pick from a list and come and go from.
One GameLift Servers fleet instance runs 6 processes, and 4 of them host Lobbies A to D (100 players each).
Inside a lobby (players present, names, chat) is handled by the game server over WebSocket, and outside the lobby (player counts in the list, notifications addressed to individuals) is delivered to the app through AppSync Events.
- Game server: GameLift Servers (Go, GameLift Go Server SDK v5.6.0)
- Lobby list, seat reservation, lobby creation: API Gateway + Lambda (Go)
- Lobby status and player display names: DynamoDB
- List updates and notifications addressed to individuals: AppSync Events
- App: Flutter (iOS simulator)
Setup
I built this with Terraform.
Here I'll only cover the parts related to lobbies.
Fleet
The fleet is On-Demand, and game session protection is set to FullProtection.
FullProtection is a setting that prevents ACTIVE game sessions from being terminated by scale-down, and the default is NoProtection.
To run 6 processes on one instance, I vary the port in each process's launch arguments in the runtime configuration (7777 to 7782).
Note that Terraform's aws_gamelift_build has no server_sdk_version argument.
I uploaded the Server SDK 5 build with the CLI's aws gamelift upload-build --server-sdk-version and passed that build ID to Terraform.
Receiving Placement Events
When creating a lobby, the lobby API asks the queue for a placement with StartGameSessionPlacement and receives the result through EventBridge.
resource "aws_cloudwatch_event_rule" "placement" {
name = var.rule_name
event_pattern = jsonencode({
source = ["aws.gamelift"]
"detail-type" = ["GameLift Queue Placement Event"]
resources = [var.queue_arn] # Only pick up events from this queue
})
}
I narrowed resources to this queue's ARN so the placement Lambda doesn't run on events from other queues.
PlacementFulfilled contains the IP address and port to connect to.
The event that actually arrived is shown below.
{
"detail-type": "GameLift Queue Placement Event",
"source": "aws.gamelift",
"region": "ap-northeast-1",
"detail": {
"placementId": "a-1796188973",
"port": "7777",
"gameSessionArn": "arn:aws:gamelift:ap-northeast-1::gamesession/<fleet-id>/a-1796188973",
"ipAddress": "<ip>",
"dnsName": "<dns>",
"startTime": "2026-12-02T05:22:53.912Z",
"endTime": "2026-12-02T05:22:54.800Z",
"type": "PlacementFulfilled"
}
}
The placement Lambda writes ACTIVE and the connection destination to DynamoDB.
For PlacementTimedOut, PlacementFailed, and PlacementCancelled, it sets the lobby to FAILED.
Player Count Reports from the Game Server
The only events GameLift sends directly to EventBridge are those for matchmaking and queue placement.
Therefore, I have the game server report the lobby's player count and the end of the game session to the lobby API.
The reports are received with API Gateway IAM authentication.
The game server receives temporary credentials for the IAM role set on the fleet (the fleet role) with GetFleetRoleCredentials and uses them to make the call.
However, GameLift managed EC2 instances run not in your own AWS account but in an account owned by GameLift.
Therefore, if you specify no credentials, the credentials of the GameLift-side account are used, and you don't have permission to call DynamoDB in your own account.
When calling DynamoDB too, I explicitly pass the fleet role credentials received with GetFleetRoleCredentials.
Closing Empty Lobbies
GameLift doesn't end empty game sessions on its own.
So I made the game server report the end to the lobby API and then call ProcessEnding to terminate once it has had 0 players for 5 minutes.
The GameLift blog also introduces a pattern where the game server calls ProcessEnding to end a world that nobody is in anymore.
When the lobby API receives the end report, it sets the lobby to dormant.
When someone tries to enter a dormant lobby, it calls StartGameSessionPlacement again to recreate the game session.
I used a DynamoDB conditional write so that placement happens only once no matter how many people come at the same time.
AppSync Events Channels
With AppSync Events, only Lambda (IAM) can publish, and the app only subscribes.
| Channel | Who can subscribe | Content |
|---|---|---|
/lobby/list |
Anyone with a token | Lobby status and player counts |
/user/{playerId} |
Only the player themselves | Notifications such as "Seat reserved" and "Starting up" |
"/user/ is only for the player themselves" is determined with Lambda authorization, by comparing the playerId in the token issued by the lobby API with the channel being subscribed to.
I don't put the connection destination in /lobby/list; the connection destination is returned only to the person who reserved a seat, in the lobby API response.
Note that AppSync Events has no official library for Dart/Flutter, so I implemented the WebSocket protocol in Dart myself.
Verification
Lobby Dormancy and Recreation
After 5 minutes with nobody entering, the lobby became dormant.
When I reserved a seat 30 seconds before it would close and waited without connecting, the lobby's closing was extended by 5 minutes, because there was a player who had reserved a seat but not yet connected.
When I tapped the dormant Lobby A, the lobby API returned 202 and recreation started.

Lobby A is "Starting", and below it appears the notification "Starting Lobby A. You'll enter automatically when it's ready." delivered through /user/{playerId}.
Once it became ACTIVE, the app entered automatically.

This time, it took 9 seconds to enter.
In another run where a free process was available, it took about 2.3 seconds from the tap until placement finished, and about 2.6 seconds until the seat was reserved.
Even when 2 people entered at the same time, or when the same person joined 90 times within 8 seconds, placement happened only once.
Events Arriving at EventBridge
When I sent all source = aws.gamelift events to CloudWatch Logs and checked, the only ones that arrived directly from GameLift were queue placement events.
The others that arrived were AWS API Call via CloudTrail events for management APIs called by the lobby API and the CLI.
Changes in player count and the end of a game session by ProcessEnding did not arrive.
This is why reports from the game server are needed.
Entering a Full Lobby
When creating a lobby, the lobby API sets the game session's MaximumPlayerSessionCount to 100.
When I put 101 bots into this Lobby A, 100 got in, and the 101st was rejected by GameLift with GameSessionFullException.
The lobby API doesn't count players itself; it converts this exception to a 409 and returns it.
However, when I spread the 101 bots over 5 seconds, about 25 got a 429 because of API Gateway throttling (20 requests per second, burst 50).
If there will be situations where many people gather, you need to decide on the limit values and the app's retry behavior.
Stopping Intake with DENY_ALL
When I set Lobby A to DENY_ALL with UpdateGameSession, CreatePlayerSession was rejected with InvalidGameSessionStatusException, and new players couldn't enter.
When I set it back to ACCEPT_ALL, they could enter again.
However, this exception is the same as when the game session isn't ACTIVE yet.
The exception alone can't distinguish "starting" from "intake stopped", so if you want to tell them apart, you also need to check PlayerSessionCreationPolicy.
Ending a Lobby
I ended Lobby D, which had one bot, through the lobby API's admin route.
The lobby API calls TerminateGameSession with TerminationMode set to TRIGGER_ON_PROCESS_TERMINATE, so the game server's OnProcessTerminate is called.
The bot received server_shutdown and then was disconnected, and Lobby D disappeared from the app's list.
FullProtection and Scale-In
I made the fleet 2 instances, put one bot in each lobby, and then reduced the count to 1 instance.
Even after 8 minutes, both instances were still Active.
When I removed one bot, that lobby closed with 0 players after about 5 minutes, and about 1.5 minutes after that, only that instance became Terminating.
The other lobby kept running with its bot still in.
Without the process that closes lobbies at 0 players, an instance with even one running lobby remains indefinitely.
Placement When Processes Are Insufficient
With game sessions on all 6 processes, I created a 7th lobby, Lobby F.
This time, the fleet was 1 instance (max also 1), and I hadn't configured a setting that automatically increases the instance count (a scaling policy).
Therefore, instances didn't increase, the placement waited for a free process, and it became PlacementTimedOut at exactly the queue's 300-second timeout, and Lobby F became "Failed to start".

When I tapped Lobby F after a process became free, it was recreated and I got in within 10 seconds.
Note that the queue's timeout (TimeoutInSeconds) can be set between 10 and 600 seconds.
Conclusion
This time, I ran GameLift Servers game sessions as lobbies and delivered the lobby list and notifications through AppSync Events.
I hope this article is helpful to someone.
