AWS for Games Blog
Building a multiplayer game with Amazon GameSparks and Amazon GameLift
Session-based multiplayer games are a popular form of online game, as they provide players with a quick, engaging experience that they can jump into at any time. However, building a scalable and reliable session-based online multiplayer game is not easy, since there are many components that need to be developed. You need game server hosting for a stable and consistent gameplay experience. You need a game backend that provides management of player identity and storage of player data, and a way to communicate with the game backend from your game. You need a matchmaking service to group players together. And finally, you need to do all of this at scale in a cost-efficient way. For many game studios, this can be challenging as it implies technologies and resources beyond their focus of making the experience fun.
In this post, you’ll learn how to combine Amazon GameSparks (currently in preview), Amazon GameLift Realtime Servers, and GameLift FlexMatch to do all of the above in a simple way. We introduce you to a sample solution that uses Amazon GameSparks as a backend for player identity, with game client connectivity to the backend provided by the GameSparks client SDK. Amazon GameSparks was launched earlier this year into preview. Currently, there are no charges for using Amazon GameSparks while in preview, though you will be charged for other AWS services you use during that time. The sample uses Amazon GameLift Realtime Servers for simple game server hosting, and GameLift FlexMatch for matchmaking. We’ll be using a sample game that you might be familiar with if you’ve played around with GameLift earlier: the Mega Frog Race Unity game that was first introduced on this AWS Game Tech blog a while ago. We’ve modified the game to work with GameSparks for this specific sample, and we’ve integrated GameLift FlexMatch as well.
Note that Amazon GameSparks is currently in preview. We don’t recommend using it for production workloads during the preview period.
The full sample for game server, game client and backend functionalities, including source code and deployment instructions, can be found in the AWS Sample GitHub repository.
Before we cover the deployment steps, here’s an overview of the components of the sample.
Overview
The following diagram illustrates the architecture of the sample solution. As you can see, several AWS services are used. We’ll explain how each of these are used in the following sections;
Serverless game backend – Amazon GameSparks
One of the most important things that we need is a service to keep track of players and their data, and allow them to initiate matchmaking requests. This is the responsibility of a game backend. In this sample, we use Amazon GameSparks for this purpose. Amazon GameSparks is a fully managed AWS service that provides a backend for game developers, allowing them to focus on building their game and leave managing and scaling cloud infrastructure to GameSparks. Amazon GameSparks also supports generating game client SDK code tailored to your unique game backend, making it easy to call functionality within GameSparks from your game’s own code, allowing you to focus on developing your game instead of specifying and implementing bidirectional network communication protocols between your backend and game client. Currently, Unity with C# are supported.
Amazon GameSparks works via messages and handlers. You define messages in the AWS Management Console by specifying what shape they have and what role they have within your backend. Several message types are supported; notifications allow the GameSparks backend to notify game clients about things that occurred in the backend. Events allow the game client to notify the GameSparks backend about things that occurred in the game. Finally, requests are a form of message type that allows a game client to send a message to the backend which expects a response from the backend. In our sample solution, we’re only using messages of the request type.
Once you’ve specified your messages, you can write handlers for them using GameSparks’ Cloud Code functionality. Handlers can perform custom logic for messages received from the game client, for instance to store and retrieve player-specific data. You implement your Cloud Code in JavaScript (ES5.1), and once deployed, GameSparks will take care of the running and execution.
Amazon GameSparks’ Cloud Code supports triggering AWS Lambda functions, which is a compute service that lets you run code without provisioning or managing servers. Lambda integrates with other AWS services, allowing you to tap into the functionality of these other services as you need for your game.
The GameSparks backend for Mega Frog Race mainly takes care of two things: starting a matchmaking request, and delivering the results back to players via a poll on the matchmaking status. In our backend solution, we’ll use a Lambda function to initiate the matchmaking request, and invoke this Lambda in response to the StartMatchmaking request via a Cloud Code request handler.
Game server hosting – Amazon GameLift Realtime Servers
Another important piece of a multiplayer game is the game server hosting. By leveraging dedicated game server hosting for our server-authoritative game, we can ensure that our players can enjoy a fast, reliable, safe and consistent gameplay experience.
For the game server hosting, we’ve selected Amazon GameLift Realtime Servers as our game server hosting platform. Realtime Servers are lightweight, customizable ready-to-go game servers that GameLift provides for use with multiplayer games that don’t need custom game servers for complex computations and physics. GameLift Realtime Servers support a Client SDK allowing easy integration between game and game server.
For other session-based games with more complex game server requirements, you could use Amazon managed GameLift together with your own dedicated game server and networking technology instead of GameLift Realtime Servers.
Matchmaking – Amazon GameLift FlexMatch
Another important part of session-based multiplayer games like Mega Frog Race is matchmaking. Matchmaking is the act of matching players together into a match, typically with certain constraints in place to ensure players of equal skill level are matched with each other.
GameLift’s game server hosting can be used with any (custom) matchmaking implementation, but for Mega Frog Race, we’ve selected GameLift FlexMatch as our matchmaking solution. With FlexMatch, you can build a custom set of rules that defines what a multiplayer match looks like for your game, and determines how to evaluate and select compatible players for each match.
As Mega Frog Race does not have a large established player base, we’ve used a very simple matchmaking configuration with no restrictions, that matches anyone to anyone else, regardless of skill level and physical location of players. However, once the game attracts more players, we may want to modify our matchmaking to provide our players with a more balanced and fun play experience. With FlexMatch in place, doing this will be pretty straightforward!
To make matchmaking status available to the game clients, we’ve implemented a best practice to allow our game to scale: we use FlexMatch event notifications to receive matchmaking events in Amazon Simple Notification Service (SNS). A Lambda function in turn takes care of processing those matchmaking events, and storing the results in DynamoDB where they can then be retrieved by the game client through a GameSparks Cloud Code request handler that reads the matchmaking status from DynamoDB directly.
Game client – Unity
Last but not least, we have our game client itself! Mega Frog Race is a simple game written in Unity, where two players compete as frogs to try to hop over to the finish line as quickly as possible, whilst trying to time their hops correctly lest they tire the frogs out. The game uses the Amazon GameSparks SDK for the connectivity between the game and the game backend, and the GameLift Realtime Client SDK for the real-time communication with our dedicated game server provided by GameLift Realtime.
Deployment
Now that we’ve discussed the various parts of the architecture, let’s examine the sample and deploy it!
The sample uses the AWS Cloud Development Kit (CDK) v2 to deploy our infrastructure. With CDK, you define your AWS infrastructure in code, and then deploy it with one press of a button. This allows you to implement software engineering best practices like code reviews for your infrastructure.
The sample consists of two CDK stacks, which deploy the game server, set up the matchmaking infrastructure, and configure IAM roles required for Amazon GameSparks to give it access to the matchmaking infrastructure. Once the CDK stacks have been deployed, you’ll need to configure the GameSparks backend via the AWS Management Console, generate the GameSparks client code, and finally load the GameSparks client SDK into the sample game project and configure it.
Before you deploy the sample, ensure you have the following requirements installed:
- an AWS account with locally configured set up credentials
- Node.js (we recommend the latest LTS version)
- Yarn
- The AWS CDK toolkit
- Prerequisites for working with CDK in TypeScript
- Git
- Unity 2020.3
- Microsoft Visual Studio 2017 or higher (any edition)
Also, make sure you download the following dependencies that are required for building our game client:
Once you have all of the above in place, we’ll start by cloning the git repository via a terminal session or our favorite Git GUI, and then change directory into the cloned repository:
git clone https://github.com/aws-samples/amazon-gamesparks-integration-with-gamelift.git
cd amazon-gamesparks-integration-with-gamelift
Deploying the backend infrastructure and game server hosting
Next, you’ll deploy the game server hosting and the parts of the backend infrastructure outside of GameSparks that involve handling of matchmaking.
From the root directory of the sample’s git repository that you checked out earlier, run the following commands to install the CDK dependencies and build the code:
yarn install --frozen-lockfile
yarn bootstrap
yarn build
Next, we’ll need to manually upload the game server .zip file to S3, and set up a local configuration file to point to the location of this file:
- Create an S3 bucket in the us-east-1 region with a name that does not contain any periods (‘.’); the bucket cannot be encrypted and should not be made public.
- Upload “packages/game-server/game-server.zip” from the sample git repository to the S3 bucket. This .zip file was generated earlier by the
yarn build
command. It’s okay to upload this file to the root of the S3 bucket when experimenting, but for a production workload, consider using a naming scheme for S3 object keys that includes a version number. - In the sample git repository, copy “packages/infra/config/infra-config.example.json” to “packages/infra/config/infra-config.json” and then open the copied “infra-config.json” file in a text editor.
- Modify the assetBucketName and assetObjectKey keys in the JSON object, such that assetBucketName contains the bucket name of the S3 bucket you created in the first step, and assetObjectKey contains the S3 object key of the file you uploaded. If you’re not sure what to use here, note that you can inspect the key when viewing the object overview in the Amazon S3 console.
Now that we’ve uploaded the game server .zip file, we’re ready to deploy the CDK stacks! From the root directory of the sample’s git repository, run the following commands:
cd packages/infra
yarn cdk synth
yarn cdk bootstrap
yarn cdk deploy "*/MatchmakingStack"
yarn cdk deploy "*/MatchmakingMgmtStack"
The CDK deployment processes may take a few minutes to complete as all of the infrastructure is provisioned and your game servers are deployed. Once either of them is finished, you’ll see something like this:
You now have the game server hosting, as well as the prerequisite game backend infrastructure deployed.
To verify that the GameLift Realtime game server is running correctly, follow these steps:
- Open the AWS Management Console and make sure you select the North Virginia (us-east-1) region.
- Navigate to the Amazon GameLift console.
- Scroll down until you see an overview of the Builds, Fleets and Aliases, and verify that you see:
- One (1) active Fleet, named SampleRealtimeFleet
- One (1) Alias, named SampleGameServerFleetAlias
- Click on the blue SampleRealtimeFleet text to inspect the fleet.
- Verify that you see:
- One (1) active instance
- One (1) active server
- Switch to the Events tab and check that there are no recent errors (for example, “SERVER_PROCESS_TERMINATED_UNHEALTHY”).
If everything deployed successfully, you are ready to set up the GameSparks backend!
Setting up the Amazon GameSparks game backend
To set up the Amazon GameSparks game backend, open the AWS Management Console, make sure you select the North Virginia (us-east-1) region, then navigate to Amazon GameSparks and select Next.
Then, use “MegaFrogRace” for the game name and use the existing “GameDeployment-MegaFrogRace” role for the Dev stage, then select Create. This role was created previously by the CDK deployment, and has been preconfigured to allow GameSparks to connect with our deployed resources.
There are two ways to set up the GameSparks game backend for the MegaFrogRace sample solution: manually via the management console, or by importing a snapshot JSON file that’s provided in the sample’s git repository. If you want to quickly get the backend running, import the snapshot JSON, though if you’re interested in making any modifications later we encourage you to set up the backend manually as this will help you understand how to set up GameSparks for your own game later.
Setting up the game backend by importing the snapshot JSON
To set up the GameSparks game backend by importing a snapshot JSON file, navigate to the game’s “Dev” stage. Then, under Snapshot, select Actions and finally Import
You’ll see the following dialog:
Select Choose file, then open the “megafrograce_gamesparks_int.json” file which you can find in the sample’s Git repository under “packages/matchmaking-mgmt/asset/megafrograce_gamesparks_int.json“. Finally, select Import to begin the import process.
The import may take a minute to complete. You can verify that it has been imported by navigating to the Dev stage’s Cloud code page via the navigation sidebar on the left. On the Cloud code page, under Requests → Custom, you should see two messages: StartMatchmaking and GetMatchmakingInfo.
That’s it! We’ve now configured our GameSparks game backend for Mega Frog Race, and are ready to deploy it and test it. You can now skip ahead to the “Deploying and testing our GameSparks game backend” section below to continue.
Setting up the game backend manually
If you’ve set up the GameSparks game backend via the snapshot JSON, you can skip this section and go straight to testing and deploying. Otherwise, read on for information on how to set up the GameSparks game backend manually!
Navigate to the GameSparks console on the AWS Management Console. In the sidebar to the left, make sure MegaFrogRace is expanded, then click on Dev to navigate to the development stage of our game. A new Configuration section will appear; click on Cloud Code beneath that to navigate to the cloud code section.
You’ll be presented with the following page:
As mentioned earlier, GameSparks works using messages and handlers. To make it easy to develop both the Cloud Code and the game client integration, you can define shapes of messages in GameSparks, and generate game client code that includes C# classes and types that map to these messages. The GameSparks backend will in turn validate that messages sent by the game client and Cloud Code conform to our specified shape, which increases the reliability of our backend. Whilst defining custom shapes is not strictly necessary (we can use a so-called “Any” type to forgo this), it is a best practice and makes the integration with the game a lot easier. If you’re familiar with web service development, this process is similar to defining a schema in OpenAPI and generating a client interface and server-side validations from that.
We’ll start by creating the MatchmakingStatus shape that encodes the status of our matchmaking request ticket as an enumeration type:
- Select Configure, this will open a drop-down menu
- Select Game-defined shapes, which navigates you to the game-defined shapes section
- Select Create shape
- In the Shape definition section, choose “MatchmakingStatus” as the Name of our new shape
- For Type, use “Enum”
- Add the following Values to the shape, exactly as shown. You can use the “Add value” button to add additional values:
- MatchmakingSearching
- PotentialMatchCreated
- MatchmakingSucceeded
- MatchmakingFailed
- MatchmakingTimedOut
- MatchmakingCancelled
- Choose a descriptive name (optional), for example “Matchmaking ticket status”
- Verify that your shape configuration matches the following:
- Select Create to finish the creation of the shape
Next, we’ll create the ConnectionInfo shape, which will contain information about how a game client can connect with our hosted game server:
- As before, select Configure, then Game-defined shapes, and then Create shape
- In the Shape definition section, choose “ConnectionInfo” as the Name of our new shape
- For Type, use “Structure”
- Add the following Fields to the shape, exactly as shown. You can use the “Add field” button to add additional fields:
- Port
- Name: Port
- Shape: Integer
- Required: Yes
- PlayerSessionID
- Name: PlayerSessionID
- Shape: String
- Required: No
- DNSName
- Name: DNSName
- Shape: String
- Required: No
- IPAddress
- Name: IPAddress
- Shape: String
- Required: Yes
- Port
- Choose a descriptive name (optional), for example “Connection info for joining a server”
- Verify that your shape configuration matches the following:
- Select Create to finish the creation of the shape
Now that we have our custom shapes defined, we can define the two requests in our game backend that will allow the game client to start a matchmaking request and get its info. We’ll start with the StartMatchmaking request, which will invoke the Lambda function that we deployed earlier via CDK:
- Navigate back to the Cloud code page for the Dev stage of MegaFrogRace
- Select Create message
- For the message type at the top, pick “Request”
- For Name, use “StartMatchmaking”
- Enter an optional description, for example “Start a matchmaking request”
- Select Create to create the message. This will navigate you to the request editor.
- Make sure the Enable client permission checkbox is checked.
- Since we don’t want to set up a request field for this request, make sure there are no request fields added by selecting Remove under Request fields if one has been set up automatically.
- This request needs only one response field. There should already be one response field partially set up; if not, select Add response field, then add the following:
- Field name: TicketId
- Shape: String
- Required: Yes
- Under Request handler, paste the following code:
// Get the current player ID
const currentPlayerId = GameSparks().CurrentPlayer().Id();
// Request a match via the Lambda function
const response = GameSparks().Lambda("RequestMatchmakingFunction").Invoke(
{
"currentPlayerId": currentPlayerId
}
);
const ticketId = response.Payload.MatchmakingTicket.TicketId;
GameSparks().Logging().Debug("Ticket ID is: " + JSON.stringify(ticketId));
// Store the ticket ID for the matchmaking request in the player data
const data = {
"TicketId": ticketId
}
GameSparks().CurrentPlayer().SetData(data);
// Return the ticket ID to the client
return GameSparks().Messaging().Response({"TicketId": ticketId});
- Verify that you have set up the request message and handler as follows:
- Select Save to save the request
Next up, we’ll need to create the GetMatchmakingInfo request that allows the game client to request the current matchmaking status from the game backend. This request gets the relevant data from DynamoDB directly; the infrastructure we deployed earlier through CDK takes care of ensuring that this info is available there.
- Navigate back to the Cloud code page for the Dev stage of MegaFrogRace if you’re not already there
- Select Create message
- For the message type at the top, pick “Request”
- For Name, use “GetMatchmakingInfo”
- Enter an optional description, for example “Get matchmaking information, including status and optionally connection info, via DynamoDB”
- Select Create to create the message. This will navigate you to the request editor.
- Make sure the Enable client permission checkbox is checked.
- Set up the following field under Request fields:
- Field name: TicketId
- Shape: String
- Required: No
- Set up the following fields under Response fields:
- Status
- Field name: Status
- Shape: MatchmakingStatus
- Required: Yes
- ConnectionInfo
- Field name: ConnectionInfo
- Shape: ConnectionInfo
- Required: No
- Status
- Under Request handler, paste the following code:
// Get the ticket ID from the request field if available, otherwise from the player data
let ticketId = message.TicketId;
if (ticketId === null || ticketId === undefined) {
const data = GameSparks().CurrentPlayer().GetData(["TicketId"]);
if (data.TicketId !== undefined) {
ticketId = data.TicketId
}
}
GameSparks().Logging().Debug("Ticket ID: " + ticketId);
// Get the Matchmaking ticket status and connection info from DynamoDB
const ddbResult = GameSparks().DynamoDB().GetItem("MatchmakingTicket", { "ticketId": ticketId });
const status = ddbResult.Item.matchmakingStatus;
GameSparks().Logging().Debug("Ticket data from DynamoDB: " + JSON.stringify(ddbResult));
// Create a local for the response object, to be returned later
const response = {
"Status": status
};
if (status === "MatchmakingSucceeded") {
// If the matchmaking succeeded, we have ConnectionInfo.
// Create the ConnectionInfo response field and add it to the response
const connectionInfo = {};
if (ddbResult.Item.port !== undefined) {
connectionInfo.Port = parseInt(ddbResult.Item.port);
}
if (ddbResult.Item.ip !== undefined) {
connectionInfo.IPAddress = ddbResult.Item.ip;
}
if (ddbResult.Item.dnsName !== undefined) {
connectionInfo.DNSName = ddbResult.Item.dnsName;
}
if (ddbResult.Item.playerSessionId !== undefined) {
connectionInfo.PlayerSessionID = ddbResult.Item.playerSessionId;
}
response.ConnectionInfo = connectionInfo;
}
// Return the response
return GameSparks().Messaging().Response(response);
- Verify that you have set up the request message and handler as follows:
- Select Save to save the request
That’s it! Now that we have these two messages defined, it’s time to deploy our cloud code to the Dev stage and perform our first test!
Deploying and testing our GameSparks game backend
Now that we have configured our GameSparks game backend, we can make our first deployment and start testing!
Navigate back to the Dev stage’s configuration page, then select Deploy as new snapshot to deploy the current configuration.
Give the snapshot description an (optional) descriptive name, then select Save to initiate the deployment process:
That’s it! We’re now done with setting up and deploying our GameSparks backend, and are ready to perform our first test. GameSparks has a test harness available which we can use to validate our implementation with simulated players, without needing to perform the game integration.
- On the GameSparks console, under MegaFrogRace → Configuration, select Test harness to navigate to the test harness interface. A new player is automatically created and connected for you.
- Select the StartMatchmaking request from the Messages pane (under Requests → Custom)
- Select Populate example to populate an example request body. Alternatively, you can also write your own request body. Since the StartMatchmaking request has no input fields, we can simply write
{}
. - Finally, select Send message to initiate a matchmaking request. If all went well, you should receive a successful response containing a TicketId, resembling the following:
- Select the GetMatchmakingInfo request from the Messages pane (under Requests → Custom)
- Fill out the Request body manually or by populating an example and editing it. This request supports both an empty body (
{}
), which will make the request handler fetch the Ticket ID from the player data as saved earlier, or you can specify a specific Ticket ID to get the matchmaking info for that ticket (for example,{"TicketId":"a27bdd4d-ebcc-46aa-87ed-147b210faed8"}
, but make sure to replace the value with the TicketId value you received from the StartMatchmaking request earlier) - Select Send message to send the request. If all went well, you should receive a successful response, but since you’re the only “player” right now, you likely will receive a matchmaking timeout as a status response:
- If you want to test a full successful matchmaking request with another virtual second player, you can invoke the RequestMatchmakingFunction Lambda function manually by testing it in the AWS Lambda Console. Use the following function input:
{"currentPlayerId": "my-test-player-id"}
. Immediately after you have invoked the Lambda function, repeat the steps from above, and you should receive “MatchmakingSucceeded” as a Status when sending a GetMatchmakingInfo request, including connection info to connect with the hosted GameLift Realtime server!
If you encountered any errors during testing, go back to the previous section and verify that you’ve set up your game backend correctly, or deploy the entire GameSparks backend by importing the snapshot JSON file as mentioned earlier in this blogpost.
Game client integration with GameSparks
Now that we’ve tested that our backend works, we’ll perform the final integration within our game client. We’ll need two things for this: the GameSparks Client SDK (download it if you haven’t yet), as well as the Client Code for our project, which we’ll generate now:
- Open the AWS Management Console and navigate to the Amazon GameSparks console
- Select to the Dev stage for MegaFrogRace
- Under the Snapshot section, select Actions, which opens a dropdown menu
- From the dropdown menu, select Generate Code
- For Game client platform, choose “Unity”
- For Language, choose “C#”
- Select Generate code. This process may take a few seconds, so we need to wait until the code has been generated.
- Once the code is available, click the Download button to download the generated Client Code for our backend.
We’ll now need to install and configure the GameSparks SDK, GameLift Realtime Client SDK and other dependencies, and load our generated Client Code into the project.
- Install the GameLift Realtime Client SDK:
- Extract the GameLift Realtime Client SDK .zip file you downloaded earlier
- Load up the solution in Visual Studio
- Restore the NuGet packages and build it from Visual Studio, making sure to target .Net 4.5
- Copy the following built files to the Unity project, which you can find under “packages/game-client/MegaFrogRace” in the sample’s Git repository:
- GameScaleRealTimeClientSDKNet45.dll
- Google.Protobuf.dll
- Log4net.dll
- SuperSocket.ClientEngine.dll
- WebSocket4Net.dll
- Setup DOTween:
- Extract the DOTween package you downloaded earlier, and copy the extracted folder to the Assets folder in the Unity project.
- (re-)open Unity and load the MegaFrogRace project
- Go to Tools → Demigiant → DOTween Utility Panel and select Setup DOTween…
- Install the Amazon GameSparks Client SDK plugin:
- Go to Window → Package Manager → + → Add package from tarball, then select the AmazonGameSparks.tgz file you downloaded earlier.
- Load the generated GameSparks Client Code into the project:
- Extract the Amazon GameSparks Client Code .zip file we generated and downloaded earlier.
- In Unity, in the Project pane, browse to the GameSparks folder.
- Right-click inside the folder and select Import New Asset.
- Select the MegaFrogRaceOperations.cs file from the extracted Client Code.
- Set up the GameSparks connection:
- On the AWS Management Console, navigate to the Amazon GameSparks console, then navigate to MegaFrogRace’s Dev stage. Under Dev stage configuration, you should see a Key; copy this to your clipboard for later.
- In Unity, go to GameSparks menu → Setup Scene → Create connection. An Assets/Amazon/GameSparks/Connection.asset should appear in your project folder.
- Select the Connection object, and then in the Inspector panel, in the Game Key field, paste the key we copied earlier:
- Open the title scene, click on Canvas, then drag the Connection object from the Project window onto the “Connection Scriptable Object” field in the Title Controller script. The Amazon GameSparks Client SDK is now set up and connected with your GameSparks backend.
You’ve now loaded the client code and all plugin dependencies! Note that the Unity project was set up previously to work with this client code; if you’ve made any changes to the GameSparks backend, you will need to make changes to the C# code in the Unity project as well.
You are now ready to play MegaFrogRace! Amazon GameSparks automatically sets up a player identity on your computer and reuses this across running instances of your game. To playtest, create a build of your game and copy it to another computer, then start up the game on both and click the “Amazon GameSparks” button to initiate a matchmaking request on both computers. After a while, you should get matched together and start playing!
Congratulations! You have now successfully deployed and configured a multiplayer game hosted on Amazon GameLift, with Amazon GameSparks providing game backend functionality!
Troubleshooting
If you encountered any issues, here are some suggestions for things to check:
- Make sure you have deployed all infrastructure (CDK stacks, GameSparks backend) in US East 1 (N. Virginia) and selected US East 1 in the GameSparks Connection Scriptable Object.
- Check if you have any changes to your GameSparks backend configuration that have not been deployed yet, and if so, deploy them as a new snapshot.
- Verify that the IAM role used by the GameSparks Dev Stage is the GameDeployment-MegaFrogRace role. If it is not, add the GameSparksBackend customer inline policy to your currently used IAM role.
- Verify via the Amazon GameLift Console that the SampleRealtimeFleet GameLift Fleet has at least 1 active server. If not, check the Events tab for any errors. To debug further, you may need to remotely access the GameLift fleet instance.
Destroying deployed infrastructure
If you are finished experimenting for today and want to stop using the resources you created, follow these steps to avoid incurring unwanted cost.
Delete the GameSparks game backend:
- Open the AWS Management Console and navigate to the Amazon GameSparks Console
- On the navigation panel on the left, under MegaFrogRace select Game Details
- Select Delete
- Follow the prompt on screen to confirm the deletion
Delete the CDK stack:
- Run the following commands from the checked-out git repository:
cd packages/infra
yarn cdk destroy "*/MatchmakingMgmtStack"
yarn cdk destroy "*/MatchmakingStack"
- Alternatively, you can delete the sample’s deployed CloudFormation stacks via the CloudFormation service console on the AWS Management Console. Make sure you delete the MatchmakingMgmtStack before the MatchmakingStack.
Recap
In this blog post you learned how you can combine Amazon GameSparks, Amazon GameLift Realtime Servers, and GameLift FlexMatch to create a session-based online multiplayer game with backend functionality and matchmaking. You deployed a sample solution into your own account, and configured the game client integration.
Want to learn more? Check out these additional resources for more information on how you can create your own (multiplayer) game experiences on AWS!