When you make Game, executing itself will not be your goal. Operation and management are very important for Game Service. FlexMatch provides Matchmaking Events, and it makes events related to GameLift tickets.
With Matchmaking events, we are able to use this features for checking issue status, match status monitoring or troubleshooting and debugging.
In this page, we are looking how to log Matchmaking events and analyze game session match patterns easily with FlexMatch Matchmaking events and CloudWatch Logs.
CloudWatch Logs is nice tool for monitoring Log streams near-realtime, ans we can make monitoring system by Logs Insight without provisioning any resources.
So, it would be good opportunity to practice!
Creating Lambda function to handle FlexMatch Matchmaking events. Select Author from scratch. You don’t need to change Permission settings for your comfort.
Set function name as game-flexmatch-event, and Runtime would be Python 3.9. Permission requires permission to record logs in CloudWatch Logs, and can be easily implemented with basic Lambda permission.
If it is possible, I recommend you to modify this source code! Let’s check how Matchmaking can be handled and what kinds of information can we get!
import json
def lambda_handler(event, context):
eventType = event['detail']['type']
if (eventType == "MatchmakingSucceeded"):
a = event['detail']['gameSessionInfo']['players'][0]['playerId']
b = event['detail']['gameSessionInfo']['players'][1]['playerId']
print("Matchmaking: " + a + "," + b)
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
This code inspects Matchmaking event ticket types and write logs for Matchmaking data. Logs printed in Lambda function send its output stream to CloudWatch Logs as default.
Access to CloudWatch Console in order to make trigger. (https://console.aws.amazon.com/cloudwatch)
Click “CloudWatch Events” on the left side of the console. Click “Get Started” or “Create Rule”.
Let’s create Rule like below. We could also configure various Targets such as SNS topic, but we are using Lambda functions(game-flexmatch-event) as Target.
Click “Logs Insight” on left side of menu.
Next queries provide Matchmaking results from log data as raw data filtering.
fields @timestamp, @message
| filter @message like /Matchmaking:/
| sort @timestamp desc
| limit 20
You are able to put this query inside of textbox in Logs Insight
stats count(*) by @message
| filter @message like /Matchmaking:/
| sort @timestamp desc
| limit 20
And result can be like below.