Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gamelift): add GameSessionQueue L2 Construct for GameLift #23266

Merged
merged 7 commits into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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', {
stevehouel marked this conversation as resolved.
Show resolved Hide resolved
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