There is a lot here.
GameLift takes care of starting as many dedicated server instances as needed to supply you with the servers, (server processes, really) that you need to host the games. During fleet creation, the number of instances is set to one. You can adjust this manually in the console. You can and should also supply scaling rules to allow the fleet to scale up and down according to demand. You will always have a float of ‘idle instances’ which are needed to accommodate new demand (i.e. an imbalance between games starting and games ending). See here:
to look at fleets in the N.Virginia region.
The procedure your matchmaking code should now go through is pretty straightforward. You need to ‘use up’ one of the running server processes. This you do by starting a game session.
See the section at the end of this answer as for HOW to make this call with GameSparks as it doesn’t support the AWS SDK like most other environments, which is available in the language of your choice:
The call to create a game session returns a GameSessionId.
The game session has player slots in it that you can reserve (for 60 seconds max) whilst the player connects. In your case you have already found all of the players and they are ready to connect. So you fill all of the player slots with players. To do this, you use the GameSessionId to call CreatePlayerSession for each of the two (or however many) players in the match that you made.
This returns the IP address and port that the player should connect to on the dedicated server. It also returns a PlayerSessionId for each of the players that are joining. Your GameSparks server (or your matchmaking server, if you are not using GameSparks) receives that and passes the information back to the client, as part of the response to the matching request that the client made earlier before all this began.
The player client connects to the IP and port it receives, and passes the player session ID to the server. We don’t determine the communication mechanism used, as this is your client talking to your server at this point. But the server must get the PlayerSessionId.
When it does, the server now needs to contact the GameLift Session management service using the GameLift Server SDK from this page:
The server has already called InitSDK() and ProcessReady() by this point and it has already responded to the onStartGameSession() callback. Now it calls AcceptPlayerSession(playerSessionId) and this lets GameLift know that the reserved slot was correctly occupied. Don’t forget that the time from CreatePlayerSession to AcceptPlayerSession must be under 60 seconds, so no reserving a slot then hanging around in a lobby, you must join right away.
So your player is in! And gameplay starts whenever your server decides. When it decides to end the game, use the GameLift Server SDK call TerminateGameSession(), then either ProcessReady() again, or ProcessEnding(). See also this page for server integration:
See also this page for client (which includes matchmaking server) integration:
Note also the availability of Game Session Queues. Game Session Queues allocate games globally to the most appropriate region where infrastructure is ready to accept it. See also here:
I want to add some notes about how to call GameLift from GameSparks too. GameSparks doesn’t support calling any of our client SDKs (which is what you would use if you are not using GameSparks i.e. much easier). So at this moment we have to go through an extra step of creating a RESTful call within GameSparks. All AWS calls need to be signed correctly, see:
Signing requests requires that the caller has an AWS Access Key and Secret Key with appropriate permissions. Let’s get that first.
Go to IAM policies:
and Create Policy. Select Create your own policy. Name the policy Gamelift. Leave description blank. Paste the following json into the policy document:
Create a user that has that policy and get the access and secret key. Go to:
and Add user. User name can be anything, but check Programmatic access and leave AWS Management Console access unchecked. Go to Next: Permissions.
Choose Attach existing policies directly. Search for the name of the policy you created, Gamelift, in the search box, and check the item with the checkbox. Go to Next: Review.
Continue to Create user. Download the .CSV file and put it somewhere safe, where you will be able to find it again. Get the keys out of the CSV file you downloaded. The access key looks like this:
and the secret key, which looks like this:
Step One complete.
This example is to build a command to list GameLift aliases. Let’s do everything in us-east-1. Make sure you have an alias in your GameLift console. Go to:
and create an alias called Test. Give it a blank description, make it a terminal type, and a termination message of “sorry”.
Step Two complete.
Let’s also talk about the format of the call.
Gamelift only uses HTTPS POST messages, not GET.
The resource URI is
If the call is to a different region this changes somewhat.
There are no query parameters.
HTTP Headers are as follows:
X-Amz-Content-SHA256 this is the hash of the payload
content-length this is the length of the payload
content-type application/x-amz-json-1.1 <! json-1.0 DOESNT WORK
X_Amz_Date this is the time of the request in ISO 8601 format. It must be at one-second resolution, i.e. do not include milliseconds in the timestamp. It is valid 15 minutes before or after the server’s current time when AWS processes it.
Authorization this is the signature string. We will worry about how to create the signature shortly. It has this format. E.g.:
AWS4-HMAC-SHA256 Credential=/20170407/us-east-1/gamelift/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target, Signature=c8997a634bed0f4ef7f3a8beaa16531f8c89cbe134dcd8671ecceaab9c2a06e3
The request body contains the payload. The payload at a minimum is
i.e. the empty JSON form. If there are request parameters, these are included in this JSON. The hash of this string and the length of the string are given in the headers.
That’s it. *Almost.
Attached to the answer is some GameSparks code. Please note that I was unable to fully test it, but I think it constains everything else you need to build the above RESTful call.
It does depend on CryptoJS v3.1.2 available from the Google Code Archive here:
specifically sha256.js and sha256hmac.js
One more thing. If you are trying this and get stuck, let me know and we will figure out how to get you going again.
Al Murray :)
[4398-gamelift-rest-call.txt|attachment](upload://soNgFhp5sxlpxFb40OKdlrwHvpt.txt) (13.5 KB)gamelift-rest-call.txtAmazon Game Services