Skip to content

Commit

Permalink
feat(gamelift): add GameSessionQueue L2 Construct for GameLift (aws#2…
Browse files Browse the repository at this point in the history
…3266)

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*
  • Loading branch information
stevehouel authored and Brennan Ho committed Feb 22, 2023
1 parent bcd299e commit 2280a74
Show file tree
Hide file tree
Showing 18 changed files with 2,273 additions and 2 deletions.
59 changes: 59 additions & 0 deletions packages/@aws-cdk/aws-gamelift/README.md
Expand Up @@ -449,6 +449,65 @@ new cloudwatch.Alarm(this, 'Alarm', {
See: [Monitoring Using CloudWatch Metrics](https://docs.aws.amazon.com/gamelift/latest/developerguide/monitoring-cloudwatch.html)
in the *Amazon GameLift Developer Guide*.

## Game session queue

The game session queue is the primary mechanism for processing new game session
requests and locating available game servers to host them. Although it is
possible to request a new game session be hosted on specific fleet or location.

The `GameSessionQueue` resource creates a placement queue that processes requests for
new game sessions. A queue uses FleetIQ algorithms to determine the best placement
locations and find an available game server, then prompts the game server to start a
new game session. Queues can have destinations (GameLift fleets or aliases), which
determine where the queue can place new game sessions. A queue can have destinations
with varied fleet type (Spot and On-Demand), instance type, and AWS Region.

```ts
declare const fleet: gamelift.BuildFleet;
declare const alias: gamelift.Alias;

const queue = new gamelift.GameSessionQueue(this, 'GameSessionQueue', {
gameSessionQueueName: 'my-queue-name',
destinations: [fleet]
});
queue.addDestination(alias);
```

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`.

```ts
declare const fleet: gamelift.BuildFleet;
declare const topic: sns.Topic;

new gamelift.GameSessionQueue(this, 'MyGameSessionQueue', {
gameSessionQueueName: 'test-gameSessionQueue',
customEventData: 'test-event-data',
allowedLocations: ['eu-west-1', 'eu-west-2'],
destinations: [fleet],
notificationTarget: topic,
playerLatencyPolicies: [{
maximumIndividualPlayerLatency: Duration.millis(100),
policyDuration: Duration.seconds(300),
}],
priorityConfiguration: {
locationOrder: [
'eu-west-1',
'eu-west-2',
],
priorityOrder: [
gamelift.PriorityType.LATENCY,
gamelift.PriorityType.COST,
gamelift.PriorityType.DESTINATION,
gamelift.PriorityType.LOCATION,
],
},
timeout: Duration.seconds(300),
});
```

See [Setting up GameLift queues for game session placement](https://docs.aws.amazon.com/gamelift/latest/developerguide/realtime-script-uploading.html)
in the *Amazon GameLift Developer Guide*.

## GameLift FleetIQ

The GameLift FleetIQ solution is a game hosting layer that supplements the full
Expand Down
9 changes: 8 additions & 1 deletion packages/@aws-cdk/aws-gamelift/lib/alias.ts
@@ -1,12 +1,13 @@
import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import { IFleet } from './fleet-base';
import { IGameSessionQueueDestination } from './game-session-queue';
import { CfnAlias } from './gamelift.generated';

/**
* Represents a Gamelift Alias for a Gamelift fleet destination.
*/
export interface IAlias extends cdk.IResource {
export interface IAlias extends cdk.IResource, IGameSessionQueueDestination {

/**
* The Identifier of the alias.
Expand Down Expand Up @@ -106,6 +107,12 @@ export abstract class AliasBase extends cdk.Resource implements IAlias {
* The ARN of the alias
*/
public abstract readonly aliasArn: string;
/**
* The ARN to put into the destination field of a game session queue
*/
public get resourceArnForDestination() {
return this.aliasArn;
}
}

/**
Expand Down
10 changes: 9 additions & 1 deletion packages/@aws-cdk/aws-gamelift/lib/fleet-base.ts
Expand Up @@ -4,6 +4,7 @@ import * as iam from '@aws-cdk/aws-iam';
import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import { Alias, AliasOptions } from './alias';
import { IGameSessionQueueDestination } from './game-session-queue';
import { GameLiftMetrics } from './gamelift-canned-metrics.generated';
import { CfnFleet } from './gamelift.generated';

Expand Down Expand Up @@ -140,7 +141,7 @@ export interface ResourceCreationLimitPolicy {
/**
* Represents a Gamelift fleet
*/
export interface IFleet extends cdk.IResource, iam.IGrantable {
export interface IFleet extends cdk.IResource, iam.IGrantable, IGameSessionQueueDestination {
/**
* The Identifier of the fleet.
*
Expand Down Expand Up @@ -535,6 +536,13 @@ export abstract class FleetBase extends cdk.Resource implements IFleet {
}).attachTo(this);
}

/**
* The ARN to put into the destination field of a game session queue
*/
public get resourceArnForDestination() {
return this.fleetArn;
}

/**
* Adds a remote locations to deploy additional instances to and manage as part of the fleet.
*
Expand Down

0 comments on commit 2280a74

Please sign in to comment.