- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
CreatePlayerSessionCommand
Reserves an open player slot in a game session for a player. New player sessions can be created in any game session with an open slot that is in ACTIVE
status and has a player creation policy of ACCEPT_ALL
. You can add a group of players to a game session with CreatePlayerSessions .
To create a player session, specify a game session ID, player ID, and optionally a set of player data.
If successful, a slot is reserved in the game session for the player and a new PlayerSessions
object is returned with a player session ID. The player references the player session ID when sending a connection request to the game session, and the game server can use it to validate the player reservation with the Amazon GameLift service. Player sessions cannot be updated.
The maximum number of players per game session is 200. It is not adjustable.
Related actions
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { GameLiftClient, CreatePlayerSessionCommand } from "@aws-sdk/client-gamelift"; // ES Modules import
// const { GameLiftClient, CreatePlayerSessionCommand } = require("@aws-sdk/client-gamelift"); // CommonJS import
const client = new GameLiftClient(config);
const input = { // CreatePlayerSessionInput
GameSessionId: "STRING_VALUE", // required
PlayerId: "STRING_VALUE", // required
PlayerData: "STRING_VALUE",
};
const command = new CreatePlayerSessionCommand(input);
const response = await client.send(command);
// { // CreatePlayerSessionOutput
// PlayerSession: { // PlayerSession
// PlayerSessionId: "STRING_VALUE",
// PlayerId: "STRING_VALUE",
// GameSessionId: "STRING_VALUE",
// FleetId: "STRING_VALUE",
// FleetArn: "STRING_VALUE",
// CreationTime: new Date("TIMESTAMP"),
// TerminationTime: new Date("TIMESTAMP"),
// Status: "RESERVED" || "ACTIVE" || "COMPLETED" || "TIMEDOUT",
// IpAddress: "STRING_VALUE",
// DnsName: "STRING_VALUE",
// Port: Number("int"),
// PlayerData: "STRING_VALUE",
// },
// };
CreatePlayerSessionCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
GameSessionId Required | string | undefined | A unique identifier for the game session to add a player to. |
PlayerId Required | string | undefined | A unique identifier for a player. Player IDs are developer-defined. |
PlayerData | string | undefined | Developer-defined information related to a player. Amazon GameLift does not use this data, so it can be formatted as needed for use in the game. |
CreatePlayerSessionCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
PlayerSession | PlayerSession | undefined | Object that describes the newly created player session record. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
GameSessionFullException | client | The game instance is currently full and cannot allow the requested player(s) to join. Clients can retry such requests immediately or after a waiting period. |
InternalServiceException | server | The service encountered an unrecoverable internal failure while processing the request. Clients can retry such requests immediately or after a waiting period. |
InvalidGameSessionStatusException | client | The requested operation would cause a conflict with the current state of a resource associated with the request and/or the game instance. Resolve the conflict before retrying. |
InvalidRequestException | client | One or more parameter values in the request are invalid. Correct the invalid parameter values before retrying. |
NotFoundException | client | The requested resources was not found. The resource was either not created yet or deleted. |
TerminalRoutingStrategyException | client | The service is unable to resolve the routing for a particular alias because it has a terminal |
UnauthorizedException | client | The client failed authentication. Clients should not retry such requests. |
GameLiftServiceException | Base exception class for all service exceptions from GameLift service. |