From 957c97b77eb68e7d6bae2257269325dbfc035f63 Mon Sep 17 00:00:00 2001 From: andyu17 Date: Mon, 13 Jan 2025 18:28:34 +0900 Subject: [PATCH 1/3] chore(docs): fix typos --- .../@aws-cdk/aws-gamelift-alpha/README.md | 526 ++++++++++-------- .../aws-gamelift-alpha/lib/build-fleet.ts | 2 +- .../@aws-cdk/aws-gamelift-alpha/lib/build.ts | 2 +- .../aws-gamelift-alpha/lib/content.ts | 2 +- .../aws-gamelift-alpha/lib/fleet-base.ts | 8 +- .../lib/game-session-queue.ts | 4 +- .../lib/matchmaking-configuration.ts | 2 +- .../@aws-cdk/aws-gamelift-alpha/lib/script.ts | 2 +- 8 files changed, 319 insertions(+), 229 deletions(-) diff --git a/packages/@aws-cdk/aws-gamelift-alpha/README.md b/packages/@aws-cdk/aws-gamelift-alpha/README.md index 8dcccd6d4c5aa..e534def71afb8 100644 --- a/packages/@aws-cdk/aws-gamelift-alpha/README.md +++ b/packages/@aws-cdk/aws-gamelift-alpha/README.md @@ -1,4 +1,5 @@ # Amazon GameLift Construct Library + --- @@ -22,24 +23,22 @@ while dynamically scaling your resource usage to meet worldwide player demand. GameLift is composed of three main components: -* GameLift FlexMatch which is a customizable matchmaking service for -multiplayer games. With FlexMatch, you can -build a custom set of rules that defines what a multiplayer match looks like -for your game, and determines how to -evaluate and select compatible players for each match. You can also customize -key aspects of the matchmaking -process to fit your game, including fine-tuning the matching algorithm. - -* GameLift hosting for custom or realtime servers which helps you deploy, -operate, and scale dedicated game servers. It regulates the resources needed to -host games, finds available game servers to host new game sessions, and puts -players into games. - -* GameLift FleetIQ to optimize the use of low-cost Amazon Elastic Compute Cloud -(Amazon EC2) Spot Instances for cloud-based game hosting. With GameLift -FleetIQ, you can work directly with your hosting resources in Amazon EC2 and -Amazon EC2 Auto Scaling while taking advantage of GameLift optimizations to -deliver inexpensive, resilient game hosting for your players +- GameLift FlexMatch which is a customizable matchmaking service for + multiplayer games. With FlexMatch, you can + build a custom set of rules that defines what a multiplayer match looks like + for your game, and determines how to + evaluate and select compatible players for each match. You can also customize + key aspects of the matchmaking + process to fit your game, including fine-tuning the matching algorithm. +- GameLift hosting for custom or realtime servers which helps you deploy, + operate, and scale dedicated game servers. It regulates the resources needed to + host games, finds available game servers to host new game sessions, and puts + players into games. +- GameLift FleetIQ to optimize the use of low-cost Amazon Elastic Compute Cloud + (Amazon EC2) Spot Instances for cloud-based game hosting. With GameLift + FleetIQ, you can work directly with your hosting resources in Amazon EC2 and + Amazon EC2 Auto Scaling while taking advantage of GameLift optimizations to + deliver inexpensive, resilient game hosting for your players This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project. It allows you to define components for your matchmaking configuration or game server fleet management system. @@ -63,11 +62,15 @@ Through a game session queue system to let FlexMatch forms matches and uses the declare const queue: gamelift.GameSessionQueue; declare const ruleSet: gamelift.MatchmakingRuleSet; -new gamelift.QueuedMatchmakingConfiguration(this, 'QueuedMatchmakingConfiguration', { - matchmakingConfigurationName: 'test-queued-config-name', - gameSessionQueues: [queue], - ruleSet: ruleSet, -}); +new gamelift.QueuedMatchmakingConfiguration( + this, + "QueuedMatchmakingConfiguration", + { + matchmakingConfigurationName: "test-queued-config-name", + gameSessionQueues: [queue], + ruleSet: ruleSet, + } +); ``` Or through a standalone version to let FlexMatch forms matches and returns match information in an event. @@ -75,13 +78,12 @@ Or through a standalone version to let FlexMatch forms matches and returns match ```ts declare const ruleSet: gamelift.MatchmakingRuleSet; -new gamelift.StandaloneMatchmakingConfiguration(this, 'StandaloneMatchmaking', { - matchmakingConfigurationName: 'test-standalone-config-name', +new gamelift.StandaloneMatchmakingConfiguration(this, "StandaloneMatchmaking", { + matchmakingConfigurationName: "test-standalone-config-name", ruleSet: ruleSet, }); ``` - More details about Game session queue are covered [below](#game-session-queue). ### Matchmaking RuleSet @@ -97,9 +99,11 @@ average skill of the two teams must be within 10 points of each other. If no match is made after 30 seconds, gradually relax the skill requirements. ```ts -new gamelift.MatchmakingRuleSet(this, 'RuleSet', { - matchmakingRuleSetName: 'my-test-ruleset', - content: gamelift.RuleSetContent.fromJsonFile(path.join(__dirname, 'my-ruleset', 'ruleset.json')), +new gamelift.MatchmakingRuleSet(this, "RuleSet", { + matchmakingRuleSetName: "my-test-ruleset", + content: gamelift.RuleSetContent.fromJsonFile( + path.join(__dirname, "my-ruleset", "ruleset.json") + ), }); ``` @@ -113,11 +117,11 @@ a historical perspective on how your Gamelift FlexMatch solution is performing. GameLift FlexMatch sends metrics to CloudWatch so that you can collect and analyze the activity of your matchmaking solution, including match acceptance -workflow, ticket consumtion. +workflow, ticket consumption. You can then use CloudWatch alarms to alert you, for example, when matches has been rejected (potential matches that were rejected by at least one player -since the last report) exceed a certain thresold which could means that you may +since the last report) exceed a certain threshold which could means that you may have an issue in your matchmaking rules. CDK provides methods for accessing GameLift FlexMatch metrics with default configuration, @@ -132,13 +136,15 @@ matchmaking configuration. declare const matchmakingRuleSet: gamelift.MatchmakingRuleSet; // Alarm that triggers when the per-second average of not placed matches exceed 10% const ruleEvaluationRatio = new cloudwatch.MathExpression({ - expression: '1 - (ruleEvaluationsPassed / ruleEvaluationsFailed)', + expression: "1 - (ruleEvaluationsPassed / ruleEvaluationsFailed)", usingMetrics: { - ruleEvaluationsPassed: matchmakingRuleSet.metricRuleEvaluationsPassed({ statistic: cloudwatch.Statistic.SUM }), - ruleEvaluationsFailed: matchmakingRuleSet.metric('ruleEvaluationsFailed'), + ruleEvaluationsPassed: matchmakingRuleSet.metricRuleEvaluationsPassed({ + statistic: cloudwatch.Statistic.SUM, + }), + ruleEvaluationsFailed: matchmakingRuleSet.metric("ruleEvaluationsFailed"), }, }); -new cloudwatch.Alarm(this, 'Alarm', { +new cloudwatch.Alarm(this, "Alarm", { metric: ruleEvaluationRatio, threshold: 0.1, evaluationPeriods: 3, @@ -146,8 +152,7 @@ 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*. - +in the _Amazon GameLift Developer Guide_. ## GameLift Hosting @@ -165,26 +170,26 @@ To troubleshoot fleet activation problems related to the server script, see [Deb Before uploading your configured game server to GameLift for hosting, package the game build files into a build directory. This directory must include all components required to run your game servers and host game sessions, including the following: -* Game server binaries – The binary files required to run the game server. A build can include binaries for multiple game -servers built to run on the same platform. For a list of supported platforms, see [Download Amazon GameLift SDKs](https://docs.aws.amazon.com/gamelift/latest/developerguide/gamelift-supported.html). +- Game server binaries – The binary files required to run the game server. A build can include binaries for multiple game + servers built to run on the same platform. For a list of supported platforms, see [Download Amazon GameLift SDKs](https://docs.aws.amazon.com/gamelift/latest/developerguide/gamelift-supported.html). -* Dependencies – Any dependent files that your game server executables require to run. Examples include assets, configuration -files, and dependent libraries. +- Dependencies – Any dependent files that your game server executables require to run. Examples include assets, configuration + files, and dependent libraries. -* Install script – A script file to handle tasks that are required to fully install your game build on GameLift hosting -servers. Place this file at the root of the build directory. GameLift runs the install script as part of fleet creation. +- Install script – A script file to handle tasks that are required to fully install your game build on GameLift hosting + servers. Place this file at the root of the build directory. GameLift runs the install script as part of fleet creation. You can set up any application in your build, including your install script, to access your resources securely on other AWS services. ```ts declare const bucket: s3.Bucket; -const build = new gamelift.Build(this, 'Build', { - content: gamelift.Content.fromBucket(bucket, "sample-asset-key") +const build = new gamelift.Build(this, "Build", { + content: gamelift.Content.fromBucket(bucket, "sample-asset-key"), }); -new CfnOutput(this, 'BuildArn', { value: build.buildArn }); -new CfnOutput(this, 'BuildId', { value: build.buildId }); +new CfnOutput(this, "BuildArn", { value: build.buildArn }); +new CfnOutput(this, "BuildId", { value: build.buildId }); ``` To specify a server SDK version you used when integrating your game server build with Amazon GameLift use the `serverSdkVersion` parameter: @@ -193,9 +198,9 @@ To specify a server SDK version you used when integrating your game server build ```ts declare const bucket: s3.Bucket; -const build = new gamelift.Build(this, 'Build', { +const build = new gamelift.Build(this, "Build", { content: gamelift.Content.fromBucket(bucket, "sample-asset-key"), - serverSdkVersion: '5.0.0', + serverSdkVersion: "5.0.0", }); ``` @@ -212,8 +217,8 @@ server script onto each instance in the fleet, placing the script files in `/loc ```ts declare const bucket: s3.Bucket; -new gamelift.Script(this, 'Script', { - content: gamelift.Content.fromBucket(bucket, "sample-asset-key") +new gamelift.Script(this, "Script", { + content: gamelift.Content.fromBucket(bucket, "sample-asset-key"), }); ``` @@ -227,14 +232,23 @@ instances and deploying them to run your game servers. You can design a fleet to fit your game's needs. ```ts -new gamelift.BuildFleet(this, 'Game server fleet', { - fleetName: 'test-fleet', - content: gamelift.Build.fromAsset(this, 'Build', path.join(__dirname, 'CustomerGameServer')), - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE), +new gamelift.BuildFleet(this, "Game server fleet", { + fleetName: "test-fleet", + content: gamelift.Build.fromAsset( + this, + "Build", + path.join(__dirname, "CustomerGameServer") + ), + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C4, + ec2.InstanceSize.LARGE + ), runtimeConfiguration: { - serverProcesses: [{ - launchPath: 'test-launch-path', - }], + serverProcesses: [ + { + launchPath: "test-launch-path", + }, + ], }, }); ``` @@ -248,33 +262,38 @@ game server executable. You can also define additional server process configurations to run other types of processes related to your game. Each server process configuration contains the following information: -* The file name and path of an executable in your game build. +- The file name and path of an executable in your game build. -* Optionally Parameters to pass to the process on launch. +- Optionally Parameters to pass to the process on launch. -* The number of processes to run concurrently. +- The number of processes to run concurrently. A GameLift instance is limited to 50 processes running concurrently. ```ts declare const build: gamelift.Build; -// Server processes can be delcared in a declarative way through the constructor -const fleet = new gamelift.BuildFleet(this, 'Game server fleet', { - fleetName: 'test-fleet', +// Server processes can be declared in a declarative way through the constructor +const fleet = new gamelift.BuildFleet(this, "Game server fleet", { + fleetName: "test-fleet", content: build, - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE), + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C4, + ec2.InstanceSize.LARGE + ), runtimeConfiguration: { - serverProcesses: [{ - launchPath: '/local/game/GameLiftExampleServer.x86_64', - parameters: '-logFile /local/game/logs/myserver1935.log -port 1935', - concurrentExecutions: 100, - }] - } + serverProcesses: [ + { + launchPath: "/local/game/GameLiftExampleServer.x86_64", + parameters: "-logFile /local/game/logs/myserver1935.log -port 1935", + concurrentExecutions: 100, + }, + ], + }, }); ``` See [Managing how game servers are launched for hosting](https://docs.aws.amazon.com/gamelift/latest/developerguide/fleets-multiprocess.html) -in the *Amazon GameLift Developer Guide*. +in the _Amazon GameLift Developer Guide_. ### Defining an instance type @@ -287,15 +306,20 @@ properties, but the type of resources cannot be changed. ```ts declare const build: gamelift.Build; -new gamelift.BuildFleet(this, 'Game server fleet', { - fleetName: 'test-fleet', +new gamelift.BuildFleet(this, "Game server fleet", { + fleetName: "test-fleet", content: build, - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C5, + ec2.InstanceSize.LARGE + ), runtimeConfiguration: { - serverProcesses: [{ - launchPath: '/local/game/GameLiftExampleServer.x86_64', - }] - } + serverProcesses: [ + { + launchPath: "/local/game/GameLiftExampleServer.x86_64", + }, + ], + }, }); ``` @@ -308,16 +332,21 @@ By default, fleet are using on demand capacity. ```ts declare const build: gamelift.Build; -new gamelift.BuildFleet(this, 'Game server fleet', { - fleetName: 'test-fleet', +new gamelift.BuildFleet(this, "Game server fleet", { + fleetName: "test-fleet", content: build, - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE), + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C4, + ec2.InstanceSize.LARGE + ), runtimeConfiguration: { - serverProcesses: [{ - launchPath: '/local/game/GameLiftExampleServer.x86_64', - }] + serverProcesses: [ + { + launchPath: "/local/game/GameLiftExampleServer.x86_64", + }, + ], }, - useSpot: true + useSpot: true, }); ``` @@ -334,22 +363,29 @@ automatically opens two port ranges, one for TCP messaging and one for UDP. ```ts declare const build: gamelift.Build; -const fleet = new gamelift.BuildFleet(this, 'Game server fleet', { - fleetName: 'test-fleet', +const fleet = new gamelift.BuildFleet(this, "Game server fleet", { + fleetName: "test-fleet", content: build, - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE), + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C4, + ec2.InstanceSize.LARGE + ), runtimeConfiguration: { - serverProcesses: [{ - launchPath: '/local/game/GameLiftExampleServer.x86_64', - }] + serverProcesses: [ + { + launchPath: "/local/game/GameLiftExampleServer.x86_64", + }, + ], }, - ingressRules: [{ - source: gamelift.Peer.anyIpv4(), - port: gamelift.Port.tcpRange(100, 200), - }] + ingressRules: [ + { + source: gamelift.Peer.anyIpv4(), + port: gamelift.Port.tcpRange(100, 200), + }, + ], }); // Allowing a specific CIDR for port 1111 on UDP Protocol -fleet.addIngressRule(gamelift.Peer.ipv4('1.2.3.4/32'), gamelift.Port.udp(1111)); +fleet.addIngressRule(gamelift.Peer.ipv4("1.2.3.4/32"), gamelift.Port.udp(1111)); ``` ### Managing locations @@ -365,34 +401,42 @@ By default, home region is used as default location but we can add new locations declare const build: gamelift.Build; // Locations can be added directly through constructor -const fleet = new gamelift.BuildFleet(this, 'Game server fleet', { - fleetName: 'test-fleet', +const fleet = new gamelift.BuildFleet(this, "Game server fleet", { + fleetName: "test-fleet", content: build, - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE), + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C4, + ec2.InstanceSize.LARGE + ), runtimeConfiguration: { - serverProcesses: [{ - launchPath: '/local/game/GameLiftExampleServer.x86_64', - }] + serverProcesses: [ + { + launchPath: "/local/game/GameLiftExampleServer.x86_64", + }, + ], }, - locations: [ { - region: 'eu-west-1', - capacity: { - desiredCapacity: 5, - minSize: 2, - maxSize: 10 - } - }, { - region: 'us-east-1', - capacity: { - desiredCapacity: 5, - minSize: 2, - maxSize: 10 - } - }] + locations: [ + { + region: "eu-west-1", + capacity: { + desiredCapacity: 5, + minSize: 2, + maxSize: 10, + }, + }, + { + region: "us-east-1", + capacity: { + desiredCapacity: 5, + minSize: 2, + maxSize: 10, + }, + }, + ], }); // Or through dedicated methods -fleet.addLocation('ap-southeast-1', 5, 2, 10); +fleet.addLocation("ap-southeast-1", 5, 2, 10); ``` ### Specifying an IAM role for a Fleet @@ -405,25 +449,34 @@ specify your own IAM role. ```ts declare const build: gamelift.Build; -const role = new iam.Role(this, 'Role', { - assumedBy: new iam.CompositePrincipal(new iam.ServicePrincipal('gamelift.amazonaws.com')) +const role = new iam.Role(this, "Role", { + assumedBy: new iam.CompositePrincipal( + new iam.ServicePrincipal("gamelift.amazonaws.com") + ), }); -role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy')); +role.addManagedPolicy( + iam.ManagedPolicy.fromAwsManagedPolicyName("CloudWatchAgentServerPolicy") +); -const fleet = new gamelift.BuildFleet(this, 'Game server fleet', { - fleetName: 'test-fleet', +const fleet = new gamelift.BuildFleet(this, "Game server fleet", { + fleetName: "test-fleet", content: build, - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C5, + ec2.InstanceSize.LARGE + ), runtimeConfiguration: { - serverProcesses: [{ - launchPath: '/local/game/GameLiftExampleServer.x86_64', - }] + serverProcesses: [ + { + launchPath: "/local/game/GameLiftExampleServer.x86_64", + }, + ], }, - role: role + role: role, }); -// Actions can also be grantted through dedicated method -fleet.grant(role, 'gamelift:ListFleets'); +// Actions can also be granted through dedicated method +fleet.grant(role, "gamelift:ListFleets"); ``` ### Alias @@ -438,17 +491,17 @@ by changing the alias's target location. declare const fleet: gamelift.BuildFleet; // Add an alias to an existing fleet using a dedicated fleet method -const liveAlias = fleet.addAlias('live'); +const liveAlias = fleet.addAlias("live"); // You can also create a standalone alias -new gamelift.Alias(this, 'TerminalAlias', { - aliasName: 'terminal-alias', - terminalMessage: 'A terminal message', +new gamelift.Alias(this, "TerminalAlias", { + aliasName: "terminal-alias", + terminalMessage: "A terminal message", }); ``` See [Add an alias to a GameLift fleet](https://docs.aws.amazon.com/gamelift/latest/developerguide/aliases-creating.html) -in the *Amazon GameLift Developer Guide*. +in the _Amazon GameLift Developer Guide_. ### Monitoring your Fleet @@ -458,7 +511,7 @@ your game servers via logs and metrics. #### Fleet Metrics GameLift Fleet sends metrics to CloudWatch so that you can collect and analyze -the activity of your Fleet, including game and player sessions and server +the activity of your Fleet, including game and player sessions and server processes. You can then use CloudWatch alarms to alert you, for example, when matches has @@ -477,13 +530,15 @@ the correct dimensions for the matchmaking configuration. declare const fleet: gamelift.BuildFleet; // Alarm that triggers when the per-second average of not used instances exceed 10% const instancesUsedRatio = new cloudwatch.MathExpression({ - expression: '1 - (activeInstances / idleInstances)', + expression: "1 - (activeInstances / idleInstances)", usingMetrics: { - activeInstances: fleet.metric('ActiveInstances', { statistic: cloudwatch.Statistic.SUM }), + activeInstances: fleet.metric("ActiveInstances", { + statistic: cloudwatch.Statistic.SUM, + }), idleInstances: fleet.metricIdleInstances(), }, }); -new cloudwatch.Alarm(this, 'Alarm', { +new cloudwatch.Alarm(this, "Alarm", { metric: instancesUsedRatio, threshold: 0.1, evaluationPeriods: 3, @@ -491,7 +546,7 @@ 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*. +in the _Amazon GameLift Developer Guide_. ## Game session queue @@ -510,47 +565,46 @@ with varied fleet type (Spot and On-Demand), instance type, and AWS Region. declare const fleet: gamelift.BuildFleet; declare const alias: gamelift.Alias; -const queue = new gamelift.GameSessionQueue(this, 'GameSessionQueue', { - gameSessionQueueName: 'my-queue-name', - destinations: [fleet] +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`. +A more complex configuration can also be defined 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), - }); +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*. +in the _Amazon GameLift Developer Guide_. ## GameLift FleetIQ @@ -580,21 +634,29 @@ dedicated Api. declare const launchTemplate: ec2.ILaunchTemplate; declare const vpc: ec2.IVpc; -new gamelift.GameServerGroup(this, 'Game server group', { - gameServerGroupName: 'sample-gameservergroup-name', - instanceDefinitions: [{ - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), - }, - { - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE), - }], +new gamelift.GameServerGroup(this, "Game server group", { + gameServerGroupName: "sample-gameservergroup-name", + instanceDefinitions: [ + { + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C5, + ec2.InstanceSize.LARGE + ), + }, + { + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C4, + ec2.InstanceSize.LARGE + ), + }, + ], launchTemplate: launchTemplate, - vpc: vpc + vpc: vpc, }); ``` See [Manage game server groups](https://docs.aws.amazon.com/gamelift/latest/fleetiqguide/gsg-integrate-gameservergroup.html) -in the *Amazon GameLift FleetIQ Developer Guide*. +in the _Amazon GameLift FleetIQ Developer Guide_. ### Scaling Policy @@ -606,25 +668,33 @@ players. declare const launchTemplate: ec2.ILaunchTemplate; declare const vpc: ec2.IVpc; -new gamelift.GameServerGroup(this, 'Game server group', { - gameServerGroupName: 'sample-gameservergroup-name', - instanceDefinitions: [{ - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), - }, - { - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE), - }], +new gamelift.GameServerGroup(this, "Game server group", { + gameServerGroupName: "sample-gameservergroup-name", + instanceDefinitions: [ + { + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C5, + ec2.InstanceSize.LARGE + ), + }, + { + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C4, + ec2.InstanceSize.LARGE + ), + }, + ], launchTemplate: launchTemplate, vpc: vpc, autoScalingPolicy: { estimatedInstanceWarmup: Duration.minutes(5), - targetTrackingConfiguration: 5 - } + targetTrackingConfiguration: 5, + }, }); ``` See [Manage game server groups](https://docs.aws.amazon.com/gamelift/latest/fleetiqguide/gsg-integrate-gameservergroup.html) -in the *Amazon GameLift FleetIQ Developer Guide*. +in the _Amazon GameLift FleetIQ Developer Guide_. ### Specifying an IAM role for GameLift @@ -636,28 +706,40 @@ specify your own IAM role. It must have the correct permissions, or FleetIQ crea declare const launchTemplate: ec2.ILaunchTemplate; declare const vpc: ec2.IVpc; -const role = new iam.Role(this, 'Role', { - assumedBy: new iam.CompositePrincipal(new iam.ServicePrincipal('gamelift.amazonaws.com'), - new iam.ServicePrincipal('autoscaling.amazonaws.com')) +const role = new iam.Role(this, "Role", { + assumedBy: new iam.CompositePrincipal( + new iam.ServicePrincipal("gamelift.amazonaws.com"), + new iam.ServicePrincipal("autoscaling.amazonaws.com") + ), }); -role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('GameLiftGameServerGroupPolicy')); - -new gamelift.GameServerGroup(this, 'Game server group', { - gameServerGroupName: 'sample-gameservergroup-name', - instanceDefinitions: [{ - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), - }, - { - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE), - }], +role.addManagedPolicy( + iam.ManagedPolicy.fromAwsManagedPolicyName("GameLiftGameServerGroupPolicy") +); + +new gamelift.GameServerGroup(this, "Game server group", { + gameServerGroupName: "sample-gameservergroup-name", + instanceDefinitions: [ + { + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C5, + ec2.InstanceSize.LARGE + ), + }, + { + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C4, + ec2.InstanceSize.LARGE + ), + }, + ], launchTemplate: launchTemplate, vpc: vpc, - role: role + role: role, }); ``` See [Controlling Access](https://docs.aws.amazon.com/gamelift/latest/fleetiqguide/gsg-iam-permissions-roles.html) -in the *Amazon GameLift FleetIQ Developer Guide*. +in the _Amazon GameLift FleetIQ Developer Guide_. ### Specifying VPC Subnets @@ -673,17 +755,25 @@ with this request, even if the Auto Scaling group is updated directly. declare const launchTemplate: ec2.ILaunchTemplate; declare const vpc: ec2.IVpc; -new gamelift.GameServerGroup(this, 'GameServerGroup', { - gameServerGroupName: 'sample-gameservergroup-name', - instanceDefinitions: [{ - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), - }, - { - instanceType: ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE), - }], +new gamelift.GameServerGroup(this, "GameServerGroup", { + gameServerGroupName: "sample-gameservergroup-name", + instanceDefinitions: [ + { + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C5, + ec2.InstanceSize.LARGE + ), + }, + { + instanceType: ec2.InstanceType.of( + ec2.InstanceClass.C4, + ec2.InstanceSize.LARGE + ), + }, + ], launchTemplate: launchTemplate, vpc: vpc, - vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC } + vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC }, }); ``` @@ -707,12 +797,12 @@ matchmaking configuration. ```ts declare const gameServerGroup: gamelift.IGameServerGroup; // Alarm that triggers when the percent of utilized game servers exceed 90% -new cloudwatch.Alarm(this, 'Alarm', { - metric: gameServerGroup.metric('UtilizedGameServers'), +new cloudwatch.Alarm(this, "Alarm", { + metric: gameServerGroup.metric("UtilizedGameServers"), threshold: 0.9, evaluationPeriods: 2, }); ``` See: [Monitoring with CloudWatch](https://docs.aws.amazon.com/gamelift/latest/fleetiqguide/gsg-metrics.html) -in the *Amazon GameLift FleetIQ Developer Guide*. +in the _Amazon GameLift FleetIQ Developer Guide_. diff --git a/packages/@aws-cdk/aws-gamelift-alpha/lib/build-fleet.ts b/packages/@aws-cdk/aws-gamelift-alpha/lib/build-fleet.ts index ae9e24a32222f..e6887eb67d707 100644 --- a/packages/@aws-cdk/aws-gamelift-alpha/lib/build-fleet.ts +++ b/packages/@aws-cdk/aws-gamelift-alpha/lib/build-fleet.ts @@ -75,7 +75,7 @@ export class BuildFleet extends FleetBase implements IBuildFleet { public readonly content: IBuild; /** - * The IAM role GameLift assumes by fleet instances to access AWS ressources. + * The IAM role GameLift assumes by fleet instances to access AWS resources. */ public readonly role: iam.IRole; diff --git a/packages/@aws-cdk/aws-gamelift-alpha/lib/build.ts b/packages/@aws-cdk/aws-gamelift-alpha/lib/build.ts index edb8ac74ee883..b968d70d34277 100644 --- a/packages/@aws-cdk/aws-gamelift-alpha/lib/build.ts +++ b/packages/@aws-cdk/aws-gamelift-alpha/lib/build.ts @@ -260,7 +260,7 @@ export class Build extends BuildBase { public readonly buildArn: string; /** - * The IAM role GameLift assumes to acccess server build content. + * The IAM role GameLift assumes to access server build content. */ public readonly role: iam.IRole; diff --git a/packages/@aws-cdk/aws-gamelift-alpha/lib/content.ts b/packages/@aws-cdk/aws-gamelift-alpha/lib/content.ts index c478aed7aa14a..e22708b3b1e61 100644 --- a/packages/@aws-cdk/aws-gamelift-alpha/lib/content.ts +++ b/packages/@aws-cdk/aws-gamelift-alpha/lib/content.ts @@ -13,7 +13,7 @@ export abstract class Content { * Game content as an S3 object. * @param bucket The S3 bucket * @param key The object key - * @param objectVersion Optional S3 ob ject version + * @param objectVersion Optional S3 object version */ public static fromBucket(bucket: s3.IBucket, key: string, objectVersion?: string): S3Content { return new S3Content(bucket, key, objectVersion); diff --git a/packages/@aws-cdk/aws-gamelift-alpha/lib/fleet-base.ts b/packages/@aws-cdk/aws-gamelift-alpha/lib/fleet-base.ts index 4446fbf7d3bbc..75b7262faa3ec 100644 --- a/packages/@aws-cdk/aws-gamelift-alpha/lib/fleet-base.ts +++ b/packages/@aws-cdk/aws-gamelift-alpha/lib/fleet-base.ts @@ -255,7 +255,7 @@ export interface FleetProps { * * You can't change this property after you create the fleet. * - * Additionnal info: + * Additional info: * AWS Certificate Manager (ACM) certificates expire after 13 months. * Certificate expiration can cause fleets to fail, preventing players from connecting to instances in the fleet. * We recommend you replace fleets before 13 months, consider using fleet aliases for a smooth transition. @@ -265,7 +265,7 @@ export interface FleetProps { readonly useCertificate?: boolean; /** - * The IAM role assumed by GameLift fleet instances to access AWS ressources. + * The IAM role assumed by GameLift fleet instances to access AWS resources. * With a role set, any application that runs on an instance in this fleet can assume the role, including install scripts, server processes, and daemons (background processes). * If providing a custom role, it needs to trust the GameLift service principal (gamelift.amazonaws.com). * No permission is required by default. @@ -396,7 +396,7 @@ export interface FleetAttributes { readonly fleetId?: string; /** - * The IAM role assumed by GameLift fleet instances to access AWS ressources. + * The IAM role assumed by GameLift fleet instances to access AWS resources. * * @default the imported fleet cannot be granted access to other resources as an `iam.IGrantable`. */ @@ -644,7 +644,7 @@ export abstract class FleetBase extends cdk.Resource implements IFleet { } protected warnVpcPeeringAuthorizations(scope: Construct): void { - cdk.Annotations.of(scope).addWarningV2('@aws-cdk/aws-gamelift:fleetAutorizeVpcPeering', [ + cdk.Annotations.of(scope).addWarningV2('@aws-cdk/aws-gamelift:fleetAuthorizeVpcPeering', [ 'To authorize the VPC peering, call the GameLift service API CreateVpcPeeringAuthorization() or use the AWS CLI command create-vpc-peering-authorization.', 'Make this call using the account that manages your non-GameLift resources.', 'See: https://docs.aws.amazon.com/gamelift/latest/developerguide/vpc-peering.html', diff --git a/packages/@aws-cdk/aws-gamelift-alpha/lib/game-session-queue.ts b/packages/@aws-cdk/aws-gamelift-alpha/lib/game-session-queue.ts index d5e0cefe9f7c1..d54c06dd1ae5c 100644 --- a/packages/@aws-cdk/aws-gamelift-alpha/lib/game-session-queue.ts +++ b/packages/@aws-cdk/aws-gamelift-alpha/lib/game-session-queue.ts @@ -18,7 +18,7 @@ export interface IGameSessionQueueDestination { } /** - * Priority to condider when placing new game sessions + * Priority to consider when placing new game sessions */ export enum PriorityType { /** @@ -294,7 +294,7 @@ export abstract class GameSessionQueueBase extends cdk.Resource implements IGame /** * 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 gameSessionQueuees), which determine where the queue can place new game sessions. + * Queues can have destinations (GameLift fleets or gameSessionQueues), 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. * * @resource AWS::GameLift::GameSessionQueue diff --git a/packages/@aws-cdk/aws-gamelift-alpha/lib/matchmaking-configuration.ts b/packages/@aws-cdk/aws-gamelift-alpha/lib/matchmaking-configuration.ts index ccd8a051b2ff0..da00fd7ce67a4 100644 --- a/packages/@aws-cdk/aws-gamelift-alpha/lib/matchmaking-configuration.ts +++ b/packages/@aws-cdk/aws-gamelift-alpha/lib/matchmaking-configuration.ts @@ -120,7 +120,7 @@ export interface MatchmakingConfigurationAttributes { * * @see https://docs.aws.amazon.com/gamelift/latest/flexmatchguide/match-notification.html * - * @default no notification target binded to imported ressource + * @default no notification target binded to imported resource */ readonly notificationTarget?: sns.ITopic; } diff --git a/packages/@aws-cdk/aws-gamelift-alpha/lib/script.ts b/packages/@aws-cdk/aws-gamelift-alpha/lib/script.ts index e0cc161cc62bb..cd425ffdfd87d 100644 --- a/packages/@aws-cdk/aws-gamelift-alpha/lib/script.ts +++ b/packages/@aws-cdk/aws-gamelift-alpha/lib/script.ts @@ -178,7 +178,7 @@ export class Script extends ScriptBase { public readonly scriptArn: string; /** - * The IAM role GameLift assumes to acccess server script content. + * The IAM role GameLift assumes to access server script content. */ public readonly role: iam.IRole; From e78caea6852c6dc85e3b48ceb777b6c575492f0f Mon Sep 17 00:00:00 2001 From: yu <77177966+andyu17@users.noreply.github.com> Date: Mon, 13 Jan 2025 21:57:49 +0900 Subject: [PATCH 2/3] Update fleet-base.ts --- packages/@aws-cdk/aws-gamelift-alpha/lib/fleet-base.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-gamelift-alpha/lib/fleet-base.ts b/packages/@aws-cdk/aws-gamelift-alpha/lib/fleet-base.ts index 75b7262faa3ec..1aa0e33aca310 100644 --- a/packages/@aws-cdk/aws-gamelift-alpha/lib/fleet-base.ts +++ b/packages/@aws-cdk/aws-gamelift-alpha/lib/fleet-base.ts @@ -644,7 +644,7 @@ export abstract class FleetBase extends cdk.Resource implements IFleet { } protected warnVpcPeeringAuthorizations(scope: Construct): void { - cdk.Annotations.of(scope).addWarningV2('@aws-cdk/aws-gamelift:fleetAuthorizeVpcPeering', [ + cdk.Annotations.of(scope).addWarningV2('@aws-cdk/aws-gamelift:fleetAutorizeVpcPeering', [ 'To authorize the VPC peering, call the GameLift service API CreateVpcPeeringAuthorization() or use the AWS CLI command create-vpc-peering-authorization.', 'Make this call using the account that manages your non-GameLift resources.', 'See: https://docs.aws.amazon.com/gamelift/latest/developerguide/vpc-peering.html', From 2300a9f09f8857330a3f0d3f788751255c3d9e31 Mon Sep 17 00:00:00 2001 From: yu <77177966+andyu17@users.noreply.github.com> Date: Tue, 14 Jan 2025 23:16:05 +0900 Subject: [PATCH 3/3] Delete packages/@aws-cdk/aws-gamelift-alpha/README.md --- .../@aws-cdk/aws-gamelift-alpha/README.md | 808 ------------------ 1 file changed, 808 deletions(-) delete mode 100644 packages/@aws-cdk/aws-gamelift-alpha/README.md diff --git a/packages/@aws-cdk/aws-gamelift-alpha/README.md b/packages/@aws-cdk/aws-gamelift-alpha/README.md deleted file mode 100644 index e534def71afb8..0000000000000 --- a/packages/@aws-cdk/aws-gamelift-alpha/README.md +++ /dev/null @@ -1,808 +0,0 @@ -# Amazon GameLift Construct Library - - - ---- - -![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge) - -> The APIs of higher level constructs in this module are experimental and under active development. -> They are subject to non-backward compatible changes or removal in any future version. These are -> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be -> announced in the release notes. This means that while you may use them, you may need to update -> your source code when upgrading to a newer version of this package. - ---- - - - -[Amazon GameLift](https://docs.aws.amazon.com/gamelift/latest/developerguide/gamelift-intro.html) is a service used -to deploy, operate, and scale dedicated, low-cost servers in the cloud for session-based multiplayer games. Built -on AWS global computing infrastructure, GameLift helps deliver high-performance, high-reliability game servers -while dynamically scaling your resource usage to meet worldwide player demand. - -GameLift is composed of three main components: - -- GameLift FlexMatch which is a customizable matchmaking service for - multiplayer games. With FlexMatch, you can - build a custom set of rules that defines what a multiplayer match looks like - for your game, and determines how to - evaluate and select compatible players for each match. You can also customize - key aspects of the matchmaking - process to fit your game, including fine-tuning the matching algorithm. -- GameLift hosting for custom or realtime servers which helps you deploy, - operate, and scale dedicated game servers. It regulates the resources needed to - host games, finds available game servers to host new game sessions, and puts - players into games. -- GameLift FleetIQ to optimize the use of low-cost Amazon Elastic Compute Cloud - (Amazon EC2) Spot Instances for cloud-based game hosting. With GameLift - FleetIQ, you can work directly with your hosting resources in Amazon EC2 and - Amazon EC2 Auto Scaling while taking advantage of GameLift optimizations to - deliver inexpensive, resilient game hosting for your players - -This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project. It allows you to define components for your matchmaking -configuration or game server fleet management system. - -## GameLift FlexMatch - -### Defining a Matchmaking configuration - -FlexMatch is available both as a GameLift game hosting solution (including -Realtime Servers) and as a standalone matchmaking service. To set up a -FlexMatch matchmaker to process matchmaking requests, you have to create a -matchmaking configuration based on a RuleSet. - -More details about matchmaking ruleSet are covered [below](#matchmaking-ruleset). - -There is two types of Matchmaking configuration: - -Through a game session queue system to let FlexMatch forms matches and uses the specified GameLift queue to start a game session for the match. - -```ts -declare const queue: gamelift.GameSessionQueue; -declare const ruleSet: gamelift.MatchmakingRuleSet; - -new gamelift.QueuedMatchmakingConfiguration( - this, - "QueuedMatchmakingConfiguration", - { - matchmakingConfigurationName: "test-queued-config-name", - gameSessionQueues: [queue], - ruleSet: ruleSet, - } -); -``` - -Or through a standalone version to let FlexMatch forms matches and returns match information in an event. - -```ts -declare const ruleSet: gamelift.MatchmakingRuleSet; - -new gamelift.StandaloneMatchmakingConfiguration(this, "StandaloneMatchmaking", { - matchmakingConfigurationName: "test-standalone-config-name", - ruleSet: ruleSet, -}); -``` - -More details about Game session queue are covered [below](#game-session-queue). - -### Matchmaking RuleSet - -Every FlexMatch matchmaker must have a rule set. The rule set determines the -two key elements of a match: your game's team structure and size, and how to -group players together for the best possible match. - -For example, a rule set might describe a match like this: Create a match with -two teams of four to eight players each, one team is the cowboy and the other -team the aliens. A team can have novice and experienced players, but the -average skill of the two teams must be within 10 points of each other. If no -match is made after 30 seconds, gradually relax the skill requirements. - -```ts -new gamelift.MatchmakingRuleSet(this, "RuleSet", { - matchmakingRuleSetName: "my-test-ruleset", - content: gamelift.RuleSetContent.fromJsonFile( - path.join(__dirname, "my-ruleset", "ruleset.json") - ), -}); -``` - -### FlexMatch Monitoring - -You can monitor GameLift FlexMatch activity for matchmaking configurations and -matchmaking rules using Amazon CloudWatch. These statistics are used to provide -a historical perspective on how your Gamelift FlexMatch solution is performing. - -#### FlexMatch Metrics - -GameLift FlexMatch sends metrics to CloudWatch so that you can collect and -analyze the activity of your matchmaking solution, including match acceptance -workflow, ticket consumption. - -You can then use CloudWatch alarms to alert you, for example, when matches has -been rejected (potential matches that were rejected by at least one player -since the last report) exceed a certain threshold which could means that you may -have an issue in your matchmaking rules. - -CDK provides methods for accessing GameLift FlexMatch metrics with default configuration, -such as `metricRuleEvaluationsPassed`, or `metricRuleEvaluationsFailed` (see -[`IMatchmakingRuleSet`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-gamelift.IMatchmakingRuleSet.html) -for a full list). CDK also provides a generic `metric` method that can be used -to produce metric configurations for any metric provided by GameLift FlexMatch; -the configurations are pre-populated with the correct dimensions for the -matchmaking configuration. - -```ts -declare const matchmakingRuleSet: gamelift.MatchmakingRuleSet; -// Alarm that triggers when the per-second average of not placed matches exceed 10% -const ruleEvaluationRatio = new cloudwatch.MathExpression({ - expression: "1 - (ruleEvaluationsPassed / ruleEvaluationsFailed)", - usingMetrics: { - ruleEvaluationsPassed: matchmakingRuleSet.metricRuleEvaluationsPassed({ - statistic: cloudwatch.Statistic.SUM, - }), - ruleEvaluationsFailed: matchmakingRuleSet.metric("ruleEvaluationsFailed"), - }, -}); -new cloudwatch.Alarm(this, "Alarm", { - metric: ruleEvaluationRatio, - threshold: 0.1, - evaluationPeriods: 3, -}); -``` - -See: [Monitoring Using CloudWatch Metrics](https://docs.aws.amazon.com/gamelift/latest/developerguide/monitoring-cloudwatch.html) -in the _Amazon GameLift Developer Guide_. - -## GameLift Hosting - -### Uploading builds and scripts to GameLift - -Before deploying your GameLift-enabled multiplayer game servers for hosting with the GameLift service, you need to upload -your game server files. This section provides guidance on preparing and uploading custom game server build -files or Realtime Servers server script files. When you upload files, you create a GameLift build or script resource, which -you then deploy on fleets of hosting resources. - -To troubleshoot fleet activation problems related to the server script, see [Debug GameLift fleet issues](https://docs.aws.amazon.com/gamelift/latest/developerguide/fleets-creating-debug.html). - -#### Upload a custom server build to GameLift - -Before uploading your configured game server to GameLift for hosting, package the game build files into a build directory. -This directory must include all components required to run your game servers and host game sessions, including the following: - -- Game server binaries – The binary files required to run the game server. A build can include binaries for multiple game - servers built to run on the same platform. For a list of supported platforms, see [Download Amazon GameLift SDKs](https://docs.aws.amazon.com/gamelift/latest/developerguide/gamelift-supported.html). - -- Dependencies – Any dependent files that your game server executables require to run. Examples include assets, configuration - files, and dependent libraries. - -- Install script – A script file to handle tasks that are required to fully install your game build on GameLift hosting - servers. Place this file at the root of the build directory. GameLift runs the install script as part of fleet creation. - -You can set up any application in your build, including your install script, to access your resources securely on other AWS -services. - -```ts -declare const bucket: s3.Bucket; -const build = new gamelift.Build(this, "Build", { - content: gamelift.Content.fromBucket(bucket, "sample-asset-key"), -}); - -new CfnOutput(this, "BuildArn", { value: build.buildArn }); -new CfnOutput(this, "BuildId", { value: build.buildId }); -``` - -To specify a server SDK version you used when integrating your game server build with Amazon GameLift use the `serverSdkVersion` parameter: - -> See [Integrate games with custom game servers](https://docs.aws.amazon.com/gamelift/latest/developerguide/integration-custom-intro.html) for more details. - -```ts -declare const bucket: s3.Bucket; -const build = new gamelift.Build(this, "Build", { - content: gamelift.Content.fromBucket(bucket, "sample-asset-key"), - serverSdkVersion: "5.0.0", -}); -``` - -#### Upload a realtime server Script - -Your server script can include one or more files combined into a single .zip file for uploading. The .zip file must contain -all files that your script needs to run. - -You can store your zipped script files in either a local file directory or in an Amazon Simple Storage Service (Amazon S3) -bucket or defines a directory asset which is archived as a .zip file and uploaded to S3 during deployment. - -After you create the script resource, GameLift deploys the script with a new Realtime Servers fleet. GameLift installs your -server script onto each instance in the fleet, placing the script files in `/local/game`. - -```ts -declare const bucket: s3.Bucket; -new gamelift.Script(this, "Script", { - content: gamelift.Content.fromBucket(bucket, "sample-asset-key"), -}); -``` - -### Defining a GameLift Fleet - -#### Creating a custom game server fleet - -Your uploaded game servers are hosted on GameLift virtual computing resources, -called instances. You set up your hosting resources by creating a fleet of -instances and deploying them to run your game servers. You can design a fleet -to fit your game's needs. - -```ts -new gamelift.BuildFleet(this, "Game server fleet", { - fleetName: "test-fleet", - content: gamelift.Build.fromAsset( - this, - "Build", - path.join(__dirname, "CustomerGameServer") - ), - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C4, - ec2.InstanceSize.LARGE - ), - runtimeConfiguration: { - serverProcesses: [ - { - launchPath: "test-launch-path", - }, - ], - }, -}); -``` - -### Managing game servers launch configuration - -GameLift uses a fleet's runtime configuration to determine the type and number -of processes to run on each instance in the fleet. At a minimum, a runtime -configuration contains one server process configuration that represents one -game server executable. You can also define additional server process -configurations to run other types of processes related to your game. Each -server process configuration contains the following information: - -- The file name and path of an executable in your game build. - -- Optionally Parameters to pass to the process on launch. - -- The number of processes to run concurrently. - -A GameLift instance is limited to 50 processes running concurrently. - -```ts -declare const build: gamelift.Build; -// Server processes can be declared in a declarative way through the constructor -const fleet = new gamelift.BuildFleet(this, "Game server fleet", { - fleetName: "test-fleet", - content: build, - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C4, - ec2.InstanceSize.LARGE - ), - runtimeConfiguration: { - serverProcesses: [ - { - launchPath: "/local/game/GameLiftExampleServer.x86_64", - parameters: "-logFile /local/game/logs/myserver1935.log -port 1935", - concurrentExecutions: 100, - }, - ], - }, -}); -``` - -See [Managing how game servers are launched for hosting](https://docs.aws.amazon.com/gamelift/latest/developerguide/fleets-multiprocess.html) -in the _Amazon GameLift Developer Guide_. - -### Defining an instance type - -GameLift uses Amazon Elastic Compute Cloud (Amazon EC2) resources, called -instances, to deploy your game servers and host game sessions for your players. -When setting up a new fleet, you decide what type of instances your game needs -and how to run game server processes on them (using a runtime configuration). All instances in a fleet use the same type of resources and the same runtime -configuration. You can edit a fleet's runtime configuration and other fleet -properties, but the type of resources cannot be changed. - -```ts -declare const build: gamelift.Build; -new gamelift.BuildFleet(this, "Game server fleet", { - fleetName: "test-fleet", - content: build, - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C5, - ec2.InstanceSize.LARGE - ), - runtimeConfiguration: { - serverProcesses: [ - { - launchPath: "/local/game/GameLiftExampleServer.x86_64", - }, - ], - }, -}); -``` - -### Using Spot instances - -When setting up your hosting resources, you have the option of using Spot -Instances, On-Demand Instances, or a combination. - -By default, fleet are using on demand capacity. - -```ts -declare const build: gamelift.Build; -new gamelift.BuildFleet(this, "Game server fleet", { - fleetName: "test-fleet", - content: build, - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C4, - ec2.InstanceSize.LARGE - ), - runtimeConfiguration: { - serverProcesses: [ - { - launchPath: "/local/game/GameLiftExampleServer.x86_64", - }, - ], - }, - useSpot: true, -}); -``` - -### Allowing Ingress traffic - -The allowed IP address ranges and port settings that allow inbound traffic to -access game sessions on this fleet. - -New game sessions are assigned an IP address/port number combination, which -must fall into the fleet's allowed ranges. Fleets with custom game builds must -have permissions explicitly set. For Realtime Servers fleets, GameLift -automatically opens two port ranges, one for TCP messaging and one for UDP. - -```ts -declare const build: gamelift.Build; - -const fleet = new gamelift.BuildFleet(this, "Game server fleet", { - fleetName: "test-fleet", - content: build, - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C4, - ec2.InstanceSize.LARGE - ), - runtimeConfiguration: { - serverProcesses: [ - { - launchPath: "/local/game/GameLiftExampleServer.x86_64", - }, - ], - }, - ingressRules: [ - { - source: gamelift.Peer.anyIpv4(), - port: gamelift.Port.tcpRange(100, 200), - }, - ], -}); -// Allowing a specific CIDR for port 1111 on UDP Protocol -fleet.addIngressRule(gamelift.Peer.ipv4("1.2.3.4/32"), gamelift.Port.udp(1111)); -``` - -### Managing locations - -A single Amazon GameLift fleet has a home Region by default (the Region you -deploy it to), but it can deploy resources to any number of GameLift supported -Regions. Select Regions based on where your players are located and your -latency needs. - -By default, home region is used as default location but we can add new locations if needed and define desired capacity - -```ts -declare const build: gamelift.Build; - -// Locations can be added directly through constructor -const fleet = new gamelift.BuildFleet(this, "Game server fleet", { - fleetName: "test-fleet", - content: build, - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C4, - ec2.InstanceSize.LARGE - ), - runtimeConfiguration: { - serverProcesses: [ - { - launchPath: "/local/game/GameLiftExampleServer.x86_64", - }, - ], - }, - locations: [ - { - region: "eu-west-1", - capacity: { - desiredCapacity: 5, - minSize: 2, - maxSize: 10, - }, - }, - { - region: "us-east-1", - capacity: { - desiredCapacity: 5, - minSize: 2, - maxSize: 10, - }, - }, - ], -}); - -// Or through dedicated methods -fleet.addLocation("ap-southeast-1", 5, 2, 10); -``` - -### Specifying an IAM role for a Fleet - -Some GameLift features require you to extend limited access to your AWS -resources. This is done by creating an AWS IAM role. The GameLift Fleet class -automatically created an IAM role with all the minimum necessary permissions -for GameLift to access your resources. If you wish, you may -specify your own IAM role. - -```ts -declare const build: gamelift.Build; -const role = new iam.Role(this, "Role", { - assumedBy: new iam.CompositePrincipal( - new iam.ServicePrincipal("gamelift.amazonaws.com") - ), -}); -role.addManagedPolicy( - iam.ManagedPolicy.fromAwsManagedPolicyName("CloudWatchAgentServerPolicy") -); - -const fleet = new gamelift.BuildFleet(this, "Game server fleet", { - fleetName: "test-fleet", - content: build, - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C5, - ec2.InstanceSize.LARGE - ), - runtimeConfiguration: { - serverProcesses: [ - { - launchPath: "/local/game/GameLiftExampleServer.x86_64", - }, - ], - }, - role: role, -}); - -// Actions can also be granted through dedicated method -fleet.grant(role, "gamelift:ListFleets"); -``` - -### Alias - -A GameLift alias is used to abstract a fleet designation. Fleet designations -tell Amazon GameLift where to search for available resources when creating new -game sessions for players. By using aliases instead of specific fleet IDs, you -can more easily and seamlessly switch player traffic from one fleet to another -by changing the alias's target location. - -```ts -declare const fleet: gamelift.BuildFleet; - -// Add an alias to an existing fleet using a dedicated fleet method -const liveAlias = fleet.addAlias("live"); - -// You can also create a standalone alias -new gamelift.Alias(this, "TerminalAlias", { - aliasName: "terminal-alias", - terminalMessage: "A terminal message", -}); -``` - -See [Add an alias to a GameLift fleet](https://docs.aws.amazon.com/gamelift/latest/developerguide/aliases-creating.html) -in the _Amazon GameLift Developer Guide_. - -### Monitoring your Fleet - -GameLift is integrated with CloudWatch, so you can monitor the performance of -your game servers via logs and metrics. - -#### Fleet Metrics - -GameLift Fleet sends metrics to CloudWatch so that you can collect and analyze -the activity of your Fleet, including game and player sessions and server -processes. - -You can then use CloudWatch alarms to alert you, for example, when matches has -been rejected (potential matches that were rejected by at least one player -since the last report) exceed a certain threshold which could means that you may -have an issue in your matchmaking rules. - -CDK provides methods for accessing GameLift Fleet metrics with default configuration, -such as `metricActiveInstances`, or `metricIdleInstances` (see [`IFleet`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-gamelift.IFleet.html) -for a full list). CDK also provides a generic `metric` method that can be used -to produce metric configurations for any metric provided by GameLift Fleet, -Game sessions or server processes; the configurations are pre-populated with -the correct dimensions for the matchmaking configuration. - -```ts -declare const fleet: gamelift.BuildFleet; -// Alarm that triggers when the per-second average of not used instances exceed 10% -const instancesUsedRatio = new cloudwatch.MathExpression({ - expression: "1 - (activeInstances / idleInstances)", - usingMetrics: { - activeInstances: fleet.metric("ActiveInstances", { - statistic: cloudwatch.Statistic.SUM, - }), - idleInstances: fleet.metricIdleInstances(), - }, -}); -new cloudwatch.Alarm(this, "Alarm", { - metric: instancesUsedRatio, - threshold: 0.1, - evaluationPeriods: 3, -}); -``` - -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 defined 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 -set of computing resource management tools that you get with Amazon EC2 and -Auto Scaling. This solution lets you directly manage your Amazon EC2 and Auto -Scaling resources and integrate as needed with other AWS services. - -### Defining a Game Server Group - -When using GameLift FleetIQ, you prepare to launch Amazon EC2 instances as -usual: make an Amazon Machine Image (AMI) with your game server software, -create an Amazon EC2 launch template, and define configuration settings for an -Auto Scaling group. However, instead of creating an Auto Scaling group -directly, you create a GameLift FleetIQ game server group with your Amazon EC2 -and Auto Scaling resources and configuration. All game server groups must have -at least two instance types defined for it. - -Once a game server group and Auto Scaling group are up and running with -instances deployed, when updating a Game Server Group instance, only certain -properties in the Auto Scaling group may be overwrite. For all other Auto -Scaling group properties, such as MinSize, MaxSize, and LaunchTemplate, you can -modify these directly on the Auto Scaling group using the AWS Console or -dedicated Api. - -```ts -declare const launchTemplate: ec2.ILaunchTemplate; -declare const vpc: ec2.IVpc; - -new gamelift.GameServerGroup(this, "Game server group", { - gameServerGroupName: "sample-gameservergroup-name", - instanceDefinitions: [ - { - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C5, - ec2.InstanceSize.LARGE - ), - }, - { - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C4, - ec2.InstanceSize.LARGE - ), - }, - ], - launchTemplate: launchTemplate, - vpc: vpc, -}); -``` - -See [Manage game server groups](https://docs.aws.amazon.com/gamelift/latest/fleetiqguide/gsg-integrate-gameservergroup.html) -in the _Amazon GameLift FleetIQ Developer Guide_. - -### Scaling Policy - -The scaling policy uses the metric `PercentUtilizedGameServers` to maintain a -buffer of idle game servers that can immediately accommodate new games and -players. - -```ts -declare const launchTemplate: ec2.ILaunchTemplate; -declare const vpc: ec2.IVpc; - -new gamelift.GameServerGroup(this, "Game server group", { - gameServerGroupName: "sample-gameservergroup-name", - instanceDefinitions: [ - { - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C5, - ec2.InstanceSize.LARGE - ), - }, - { - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C4, - ec2.InstanceSize.LARGE - ), - }, - ], - launchTemplate: launchTemplate, - vpc: vpc, - autoScalingPolicy: { - estimatedInstanceWarmup: Duration.minutes(5), - targetTrackingConfiguration: 5, - }, -}); -``` - -See [Manage game server groups](https://docs.aws.amazon.com/gamelift/latest/fleetiqguide/gsg-integrate-gameservergroup.html) -in the _Amazon GameLift FleetIQ Developer Guide_. - -### Specifying an IAM role for GameLift - -The GameLift FleetIQ class automatically creates an IAM role with all the minimum necessary -permissions for GameLift to access your Amazon EC2 Auto Scaling groups. If you wish, you may -specify your own IAM role. It must have the correct permissions, or FleetIQ creation or resource usage may fail. - -```ts -declare const launchTemplate: ec2.ILaunchTemplate; -declare const vpc: ec2.IVpc; - -const role = new iam.Role(this, "Role", { - assumedBy: new iam.CompositePrincipal( - new iam.ServicePrincipal("gamelift.amazonaws.com"), - new iam.ServicePrincipal("autoscaling.amazonaws.com") - ), -}); -role.addManagedPolicy( - iam.ManagedPolicy.fromAwsManagedPolicyName("GameLiftGameServerGroupPolicy") -); - -new gamelift.GameServerGroup(this, "Game server group", { - gameServerGroupName: "sample-gameservergroup-name", - instanceDefinitions: [ - { - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C5, - ec2.InstanceSize.LARGE - ), - }, - { - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C4, - ec2.InstanceSize.LARGE - ), - }, - ], - launchTemplate: launchTemplate, - vpc: vpc, - role: role, -}); -``` - -See [Controlling Access](https://docs.aws.amazon.com/gamelift/latest/fleetiqguide/gsg-iam-permissions-roles.html) -in the _Amazon GameLift FleetIQ Developer Guide_. - -### Specifying VPC Subnets - -GameLift FleetIQ use by default, all supported GameLift FleetIQ Availability -Zones in your chosen region. You can override this parameter to specify VPCs -subnets that you've set up. - -This property cannot be updated after the game server group is created, and the -corresponding Auto Scaling group will always use the property value that is set -with this request, even if the Auto Scaling group is updated directly. - -```ts -declare const launchTemplate: ec2.ILaunchTemplate; -declare const vpc: ec2.IVpc; - -new gamelift.GameServerGroup(this, "GameServerGroup", { - gameServerGroupName: "sample-gameservergroup-name", - instanceDefinitions: [ - { - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C5, - ec2.InstanceSize.LARGE - ), - }, - { - instanceType: ec2.InstanceType.of( - ec2.InstanceClass.C4, - ec2.InstanceSize.LARGE - ), - }, - ], - launchTemplate: launchTemplate, - vpc: vpc, - vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC }, -}); -``` - -### FleetIQ Monitoring - -GameLift FleetIQ sends metrics to CloudWatch so that you can collect and -analyze the activity of your Game server fleet, including the number of -utilized game servers, and the number of game server interruption due to -limited Spot availability. - -You can then use CloudWatch alarms to alert you, for example, when the portion -of game servers that are currently supporting game executions exceed a certain -threshold which could means that your autoscaling policy need to be adjust to -add more instances to match with player demand. - -CDK provides a generic `metric` method that can be used -to produce metric configurations for any metric provided by GameLift FleetIQ; -the configurations are pre-populated with the correct dimensions for the -matchmaking configuration. - -```ts -declare const gameServerGroup: gamelift.IGameServerGroup; -// Alarm that triggers when the percent of utilized game servers exceed 90% -new cloudwatch.Alarm(this, "Alarm", { - metric: gameServerGroup.metric("UtilizedGameServers"), - threshold: 0.9, - evaluationPeriods: 2, -}); -``` - -See: [Monitoring with CloudWatch](https://docs.aws.amazon.com/gamelift/latest/fleetiqguide/gsg-metrics.html) -in the _Amazon GameLift FleetIQ Developer Guide_.