Skip to content

Commit 1ded644

Browse files
authored
feat(gamelift): add GameSessionQueue L2 Construct for GameLift (#23266)
Following aws/aws-cdk-rfcs#436 I have written the Gamelift GameSessionQueue L2 resource which create an GameSessionQueue resource. ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 3ddb8cf commit 1ded644

18 files changed

+2273
-2
lines changed

packages/@aws-cdk/aws-gamelift/README.md

+59
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,65 @@ new cloudwatch.Alarm(this, 'Alarm', {
449449
See: [Monitoring Using CloudWatch Metrics](https://docs.aws.amazon.com/gamelift/latest/developerguide/monitoring-cloudwatch.html)
450450
in the *Amazon GameLift Developer Guide*.
451451

452+
## Game session queue
453+
454+
The game session queue is the primary mechanism for processing new game session
455+
requests and locating available game servers to host them. Although it is
456+
possible to request a new game session be hosted on specific fleet or location.
457+
458+
The `GameSessionQueue` resource creates a placement queue that processes requests for
459+
new game sessions. A queue uses FleetIQ algorithms to determine the best placement
460+
locations and find an available game server, then prompts the game server to start a
461+
new game session. Queues can have destinations (GameLift fleets or aliases), which
462+
determine where the queue can place new game sessions. A queue can have destinations
463+
with varied fleet type (Spot and On-Demand), instance type, and AWS Region.
464+
465+
```ts
466+
declare const fleet: gamelift.BuildFleet;
467+
declare const alias: gamelift.Alias;
468+
469+
const queue = new gamelift.GameSessionQueue(this, 'GameSessionQueue', {
470+
gameSessionQueueName: 'my-queue-name',
471+
destinations: [fleet]
472+
});
473+
queue.addDestination(alias);
474+
```
475+
476+
A more complex configuration can also be definied to override how FleetIQ algorithms prioritize game session placement in order to favour a destination based on `Cost`, `Latency`, `Destination order`or `Location`.
477+
478+
```ts
479+
declare const fleet: gamelift.BuildFleet;
480+
declare const topic: sns.Topic;
481+
482+
new gamelift.GameSessionQueue(this, 'MyGameSessionQueue', {
483+
gameSessionQueueName: 'test-gameSessionQueue',
484+
customEventData: 'test-event-data',
485+
allowedLocations: ['eu-west-1', 'eu-west-2'],
486+
destinations: [fleet],
487+
notificationTarget: topic,
488+
playerLatencyPolicies: [{
489+
maximumIndividualPlayerLatency: Duration.millis(100),
490+
policyDuration: Duration.seconds(300),
491+
}],
492+
priorityConfiguration: {
493+
locationOrder: [
494+
'eu-west-1',
495+
'eu-west-2',
496+
],
497+
priorityOrder: [
498+
gamelift.PriorityType.LATENCY,
499+
gamelift.PriorityType.COST,
500+
gamelift.PriorityType.DESTINATION,
501+
gamelift.PriorityType.LOCATION,
502+
],
503+
},
504+
timeout: Duration.seconds(300),
505+
});
506+
```
507+
508+
See [Setting up GameLift queues for game session placement](https://docs.aws.amazon.com/gamelift/latest/developerguide/realtime-script-uploading.html)
509+
in the *Amazon GameLift Developer Guide*.
510+
452511
## GameLift FleetIQ
453512

454513
The GameLift FleetIQ solution is a game hosting layer that supplements the full

packages/@aws-cdk/aws-gamelift/lib/alias.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import * as cdk from '@aws-cdk/core';
22
import { Construct } from 'constructs';
33
import { IFleet } from './fleet-base';
4+
import { IGameSessionQueueDestination } from './game-session-queue';
45
import { CfnAlias } from './gamelift.generated';
56

67
/**
78
* Represents a Gamelift Alias for a Gamelift fleet destination.
89
*/
9-
export interface IAlias extends cdk.IResource {
10+
export interface IAlias extends cdk.IResource, IGameSessionQueueDestination {
1011

1112
/**
1213
* The Identifier of the alias.
@@ -106,6 +107,12 @@ export abstract class AliasBase extends cdk.Resource implements IAlias {
106107
* The ARN of the alias
107108
*/
108109
public abstract readonly aliasArn: string;
110+
/**
111+
* The ARN to put into the destination field of a game session queue
112+
*/
113+
public get resourceArnForDestination() {
114+
return this.aliasArn;
115+
}
109116
}
110117

111118
/**

packages/@aws-cdk/aws-gamelift/lib/fleet-base.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as iam from '@aws-cdk/aws-iam';
44
import * as cdk from '@aws-cdk/core';
55
import { Construct } from 'constructs';
66
import { Alias, AliasOptions } from './alias';
7+
import { IGameSessionQueueDestination } from './game-session-queue';
78
import { GameLiftMetrics } from './gamelift-canned-metrics.generated';
89
import { CfnFleet } from './gamelift.generated';
910

@@ -140,7 +141,7 @@ export interface ResourceCreationLimitPolicy {
140141
/**
141142
* Represents a Gamelift fleet
142143
*/
143-
export interface IFleet extends cdk.IResource, iam.IGrantable {
144+
export interface IFleet extends cdk.IResource, iam.IGrantable, IGameSessionQueueDestination {
144145
/**
145146
* The Identifier of the fleet.
146147
*
@@ -535,6 +536,13 @@ export abstract class FleetBase extends cdk.Resource implements IFleet {
535536
}).attachTo(this);
536537
}
537538

539+
/**
540+
* The ARN to put into the destination field of a game session queue
541+
*/
542+
public get resourceArnForDestination() {
543+
return this.fleetArn;
544+
}
545+
538546
/**
539547
* Adds a remote locations to deploy additional instances to and manage as part of the fleet.
540548
*

0 commit comments

Comments
 (0)