GameLift cli - Is there a way to terminate a game session?

0

My server processes can get into a bad state, and I'd like to be able to terminate the process via the gamelift cli. Is there a way to do that? I may be missing it, but I'm not seeing anything in the docs that sounds like "delete-game-session" or "terminate-game-session".

asked 24 days ago58 views
2 Answers
1

Unfortunately there is no way to terminate the process via API. But you can combine APIs to interact with the process by accessing the instance.

  1. get the instance information using DescribeGameSessions API combined with DescribeInstances API.
  2. get the credential to access the instance using GetComputeAccess API.
  3. execute a script using Systems Manager's Session Manager, Start-Session API (or CLI).

I didn't dig into the start session part for executing the script but you can find some examples from internet. If you need to automate the process related with some events, you can implement Automation of Systems Manager or State Machine of Step Functions.

I hope this answer give you a guide to invest.

AWS
answered 23 days ago
0
Accepted Answer

Thanks for the feedback! It confirmed what I was thinking. I have since created a script much like what you described. I'll describe it below in case it helps someone in the future.

Using an IAM user with sufficient permissions, I do the following:

aws gamelift describe-fleet-capacity

aws gamelift describe-fleet-attributes - I use this to get attributes and server names to double-check in-game and other places

loop through fleet capacities

"aws gamelift describe-game-sessions --fleet-id $fleet_id --status-filter ACTIVE" for each fleet capacity to get all game sessions

Look at each game session to find those with 0 player sessions

If the game session is "too old", I call "aws gamelift describe-instances --fleet-id $fleet_id --region $cur_region" to get the instanceId

get instance details with "aws gamelift get-instance-access --instance-id $instance_id --fleet-id $fleet_id --region $cur_region"

extract the private ssh key and os username and dump into a local file; chmod 400 on that thing

use "ssh -i gamelift-temp-instance-key.pem -o "StrictHostKeyChecking no" $user_name@$ipAddress "ps -aux | grep $partial_os_username_in_ps | grep $port_gamelift" to get the processId that's running the game session on the corresponding port.

Use something like this to dump the gameserver log locally (in this case the gameserver writes to a file instead of stdout, so I can't use "aws gamelift get-game-sesison-log"): "ssh -i gamelift-temp-instance-key.pem -o "StrictHostKeyChecking no" $user_name@$ipAddress "cat /local/game/Logs/$os_pid" > ./logsamples/Server_processId_$($os_pid)_WAITING_PLACEMENT-$($ipAddress).log"

And then I kill the gameserver process with something like this: ssh -i gamelift-temp-instance-key.pem -o "StrictHostKeyChecking no" $user_name@$ipAddress "sudo kill $os_pid"

answered 22 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions