- Newest
- Most votes
- Most comments
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"
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.
- get the instance information using DescribeGameSessions API combined with DescribeInstances API.
- get the credential to access the instance using GetComputeAccess API.
- 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.
Relevant content
- asked 3 years ago
- asked 2 years ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago