In this Lab, we are starting FlexMatch Matchmaking based on Serverless Architecture.
With FlexMatch, you can implement session based matchmaker easily without provisioning servers for it. To use FlexMatch, you need to call FlexMatch API or SDK on game server or game client side. In this Lab, we are using Lambda. This approach can allow cost-efficient serverless model on your game server backend.
We are going to use GameLift Queue for matchmaking.
Nextly, we are making rule for FlexMatch. Click “Create matchmaking rule set” button.
Set rule set name as you want, and put rule set policy below on “Rule set box”. Rule set is provided from GomokuRuleSet.json under the rootFolder/Ruleset directory on a given source code. Copy the code and paste it to console box.
{
"ruleLanguageVersion" : "1.0",
"playerAttributes" :
[
{
"name" : "score",
"type" : "number",
"default" : 1000
}
],
"teams" :
[
{
"name" : "blue",
"maxPlayers" : 1,
"minPlayers" : 1
},
{
"name" : "red",
"maxPlayers" : 1,
"minPlayers" : 1
}
],
"rules" :
[
{ "name": "EqualTeamSizes",
"type": "comparison",
"measurements": [ "count(teams[red].players)" ],
"referenceValue": "count(teams[blue].players)",
"operation": "="
},
{
"name" : "FairTeamSkill",
"type" : "distance",
"measurements" : [ "avg(teams[*].players.attributes[score])" ],
"referenceValue" : "avg(flatten(teams[*].players.attributes[score]))",
"maxDistance" : 300
}
],
"expansions" :
[
{
"target" : "rules[FairTeamSkill].maxDistance",
"steps" :
[
{
"waitTimeSeconds" : 10,
"value" : 500
},
{
"waitTimeSeconds" : 20,
"value" : 800
},
{
"waitTimeSeconds" : 30,
"value" : 1000
}
]
}
]
}
This rule matches players that have score differences under 300, and if match cannot be accepted in time, mitigate matchmaking rule and find players!
Click “Validate rule set”, and check rule set is fine. And click “Create rule set”.
If you deploy CloudFormation stack, Lambda functions have already been made. You should just put required part of these resources.
GameLift FlexMatch configuration was completed!
Next step is building Lambda function and API Gateway that game client makes request for FlexMatch.
In this lab, we are going to make two Lambda functions. First one is handling matchmaking requests from client, second one is checking matchmaking results.
Let’s make first Lambda function. It will not be difficult!
Move to Lambda Console. https://console.aws.amazon.com/lambda
Click “Create function” button.
Check “Author from scratch”.
Put the Name of the function “game-match-request”.
Choose Python 3.9 as Runtime.
Choose Role on Permissions Tab. Check “Use an existing role” and select “Gomok-game-match-request” as IAM Role. Click “Create function” button.
Click “Save” button and make function. This function receives Matchmaking requests from game client, reads user data from DynamoDB and send Matchmaking requests to GameLift.
Click “Create function” button and let’s make second function.
Check “Author from scratch” and start with empty function.
Put “game-match-status” as Name, and select Python 3.9 as Runtime.
Choose Role on Permissions Tab. Check “Use an existing role” and select “Gomok-game-match-status” as IAM Role. Click “Create function” button.
Find Lambda/MatchStatus.py at your source code. Copy source code and paste it to Lambda Code textbox.
Please check Lambda functions Handler. Lambda function can access this handler when it is executed.
Let’s make API for these Lambda functions.
Move to API Gateway console. (https://console.aws.amazon.com/apigateway)
Choose API Gateway that is already made, and click “Create Resource” button.
Create new method for this resource. Click “Actions” button and “Create Method”. Make API for “POST” method.
Select Integration type with Lambda function, and check correct region. Choose game-match-request for Lambda function and click “Save” button.
Make second API for second Lambda function. Click “Actions” on the root path and “Create Resource”.
Create API as we had. Resource Name will be matchstatus and enable API Gateway CORS.
Making POST method, and integrate with game-match-status Lambda function. Click “Save” button.
Now we finish to make APIs for Lambda functions. Let’s deploy this API. Click “Actions” button and “Deploy API”.