From 7f71d4d58f218e1f43af68c5df6362e9d54d970d Mon Sep 17 00:00:00 2001 From: Steve Houel Date: Thu, 3 Nov 2022 08:26:30 +0100 Subject: [PATCH 1/5] Add GameServerGroup construct --- .../aws-gamelift/lib/game-server-group.ts | 563 ++++++++++++++++++ packages/@aws-cdk/aws-gamelift/lib/index.ts | 1 + .../test/game-server-group.test.ts | 70 +++ 3 files changed, 634 insertions(+) create mode 100644 packages/@aws-cdk/aws-gamelift/lib/game-server-group.ts create mode 100644 packages/@aws-cdk/aws-gamelift/test/game-server-group.test.ts diff --git a/packages/@aws-cdk/aws-gamelift/lib/game-server-group.ts b/packages/@aws-cdk/aws-gamelift/lib/game-server-group.ts new file mode 100644 index 0000000000000..11f08bbbd59dd --- /dev/null +++ b/packages/@aws-cdk/aws-gamelift/lib/game-server-group.ts @@ -0,0 +1,563 @@ +import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; +import * as ec2 from '@aws-cdk/aws-ec2'; +import * as iam from '@aws-cdk/aws-iam'; +import * as cdk from '@aws-cdk/core'; +import { Construct } from 'constructs'; +import { CfnGameServerGroup } from './gamelift.generated'; + + +/** + * Configuration settings for intelligent automatic scaling that uses target tracking. + * After the Auto Scaling group is created, all updates to Auto Scaling policies, including changing this policy and adding or removing other policies, is done directly on the Auto Scaling group. + */ +export interface AutoScalingPolicy { + /** + * Length of time, it takes for a new instance to start new game server processes and register with GameLift FleetIQ. + * Specifying a warm-up time can be useful, particularly with game servers that take a long time to start up, because it avoids prematurely starting new instances. + * + * @default no instance warmup duration settled + */ + readonly estimatedInstanceWarmup?: cdk.Duration; + + /** + * Settings for a target-based scaling policy applied to Auto Scaling group. + * These settings are used to create a target-based policy that tracks the GameLift FleetIQ metric `PercentUtilizedGameServers` and specifies a target value for the metric. + * + * As player usage changes, the policy triggers to adjust the game server group capacity so that the metric returns to the target value. + */ + readonly targetTrackingConfiguration: number; + +} +/** + * An allowed instance type for a game server group. + * All game server groups must have at least two instance types defined for it. + * GameLift FleetIQ periodically evaluates each defined instance type for viability. + * It then updates the Auto Scaling group with the list of viable instance types. + */ +export interface InstanceDefinition { + /** + * An Amazon EC2 instance type designation. + */ + readonly instanceType: ec2.InstanceType; + /** + * Instance weighting that indicates how much this instance type contributes to the total capacity of a game server group. + * Instance weights are used by GameLift FleetIQ to calculate the instance type's cost per unit hour and better identify the most cost-effective options. + * + * @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-instance-weighting.html + * + * @default default value is 1 + */ + readonly weight?: number; +} +/** + * The type of delete to perform. + * To delete a game server group, specify the DeleteOption. + */ +export enum DeleteOption { + /** + * Terminates the game server group and Amazon EC2 Auto Scaling group only when it has no game servers that are in UTILIZED status. + */ + SAFE_DELETE = 'SAFE_DELETE', + /** + * Terminates the game server group, including all active game servers regardless of their utilization status, and the Amazon EC2 Auto Scaling group. + */ + FORCE_DELETE = 'FORCE_DELETE', + /** + * Does a safe delete of the game server group but retains the Amazon EC2 Auto Scaling group as is. + */ + RETAIN = 'RETAIN', +} +/** + * Indicates how GameLift FleetIQ balances the use of Spot Instances and On-Demand Instances in the game server group. + */ +export enum BalancingStrategy { + /** + * Only Spot Instances are used in the game server group. + * If Spot Instances are unavailable or not viable for game hosting, the game server group provides no hosting capacity until Spot Instances can again be used. + * Until then, no new instances are started, and the existing nonviable Spot Instances are terminated (after current gameplay ends) and are not replaced. + */ + SPOT_ONLY = 'SPOT_ONLY', + /** + * Spot Instances are used whenever available in the game server group. + * If Spot Instances are unavailable, the game server group continues to provide hosting capacity by falling back to On-Demand Instances. + * Existing nonviable Spot Instances are terminated (after current gameplay ends) and are replaced with new On-Demand Instances. + */ + SPOT_PREFERRED = 'SPOT_PREFERRED', + /** + * Only On-Demand Instances are used in the game server group. + * No Spot Instances are used, even when available, while this balancing strategy is in force. + */ + ON_DEMAND_ONLY = 'ON_DEMAND_ONLY', + +} +/** + * Represent a GameLift FleetIQ game server group. + */ +export interface IGameServerGroup extends cdk.IResource, iam.IGrantable { + /** + * The ARN of the game server group. + * + * @attribute + */ + readonly gameServerGroupArn: string; + + /** + * The ARN of the generated AutoScaling group + * + * @attribute + */ + readonly autoScalingGroupArn: string; + + /** + * The name of the game server group + * + * @attribute + */ + readonly gameServerGroupName: string; + + /** + * Grant the `grantee` identity permissions to perform `actions`. + */ + grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant; + + /** + * Return the given named metric for this fleet. + */ + metric(metricName: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric; +} + +/** + * Base class for new and imported GameLift FleetIQ game server group. + */ +export abstract class GameServerGroupBase extends cdk.Resource implements IGameServerGroup { + + /** + * The ARN of the game server group. + */ + public abstract readonly gameServerGroupArn: string; + + /** + * The ARN of the generated AutoScaling group + */ + public abstract readonly autoScalingGroupArn: string; + + /** + * The name of the game server group. + */ + public abstract readonly gameServerGroupName: string; + + /** + * The principal this GameLift game server group is using. + */ + public abstract readonly grantPrincipal: iam.IPrincipal; + + public grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant { + return iam.Grant.addToPrincipal({ + resourceArns: [this.gameServerGroupArn], + grantee: grantee, + actions: actions, + }); + } + + public metric(metricName: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric { + return new cloudwatch.Metric({ + namespace: 'AWS/GameLift', + metricName: metricName, + dimensionsMap: { + GameServerGroupArn: this.gameServerGroupArn, + }, + ...props, + }).attachTo(this); + } + +} + +/** + * Represents a GameServerGroup content defined outside of this stack. + */ +export interface GameServerGroupAttributes { + + /** + * The name of the game server group + * + * At least one of `gameServerGroupArn` and `gameServerGroupName` must be provided. + * + * @default derived from `gameServerGroupArn`. + */ + readonly gameServerGroupName?: string; + /** + * The ARN of the game server group + * + * At least one of `gameServerGroupArn` and `gameServerGroupName` must be provided. + * + * @default derived from `gameServerGroupName`. + */ + readonly gameServerGroupArn?: string; + + /** + * The ARN of the generated AutoScaling group + * + * @default the imported game server group does not have autoscaling group information + */ + readonly autoScalingGroupArn: string; + + /** + * The IAM role that allows Amazon GameLift to access your Amazon EC2 Auto Scaling groups. + * + * @default the imported game server group cannot be granted access to other resources as an `iam.IGrantable`. + */ + readonly role?: iam.IRole; +} + +/** + * Properties for a new Gamelift FleetIQ Game server group + */ +export interface GameServerGroupProps { + /** + * A developer-defined identifier for the game server group. + * The name is unique for each Region in each AWS account. + */ + readonly gameServerGroupName: string; + + /** + * The IAM role that allows Amazon GameLift to access your Amazon EC2 Auto Scaling groups. + * + * @see https://docs.aws.amazon.com/gamelift/latest/fleetiqguide/gsg-iam-permissions-roles.html + * + * @default - a role will be created with default trust to Gamelift and Autoscaling service principal with a default policy `GameLiftGameServerGroupPolicy` attached. + */ + readonly role?: iam.IRole; + + /** + * The minimum number of instances allowed in the Amazon EC2 Auto Scaling group. + * During automatic scaling events, GameLift FleetIQ and Amazon EC2 do not scale down the group below this minimum. + * + * In production, this value should be set to at least 1. + * + * After the Auto Scaling group is created, update this value directly in the Auto Scaling group using the AWS console or APIs. + * + * @default the default is 0 + */ + readonly minSize?: number; + + /** + * The maximum number of instances allowed in the Amazon EC2 Auto Scaling group. During automatic scaling events, GameLift FleetIQ and EC2 do not scale up the group above this maximum. + * + * After the Auto Scaling group is created, update this value directly in the Auto Scaling group using the AWS console or APIs. + * + * @default the default is 1 + */ + readonly maxSize?: number; + + /** + * The VPC network to place the game server group in. + * + * By default, all GameLift FleetIQ-supported Availability Zones are used. + * + * You can use this parameter to specify VPCs 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. + */ + readonly vpc: ec2.IVpc; + + /** + * Game server group subnet selection + * + * @default all GameLift FleetIQ-supported Availability Zones are used. + */ + readonly vpcSubnets?: ec2.SubnetSelection; + + /** + * The set of Amazon EC2 instance types that GameLift FleetIQ can use when balancing and automatically scaling instances in the corresponding Auto Scaling group. + */ + readonly instanceDefinitions: InstanceDefinition[]; + + /** + * The Amazon EC2 launch template that contains configuration settings and game server code to be deployed to all instances in the game server group. + * After the Auto Scaling group is created, update this value directly in the Auto Scaling group using the AWS console or APIs. + * + * NOTE: + * If you specify network interfaces in your launch template, you must explicitly set the property AssociatePublicIpAddress to `true`. + * If no network interface is specified in the launch template, GameLift FleetIQ uses your account's default VPC. + * + * @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-launch-template.html + */ + readonly launchTemplate: ec2.ILaunchTemplate; + + /** + * A flag that indicates whether instances in the game server group are protected from early termination. + * Unprotected instances that have active game servers running might be terminated during a scale-down event, causing players to be dropped from the game. + * Protected instances cannot be terminated while there are active game servers running except in the event of a forced game server group deletion. + * + * An exception to this is with Spot Instances, which can be terminated by AWS regardless of protection status. + * + * @default game servers running might be terminated during a scale-down event + */ + readonly protectGameServer?: boolean; + + /** + * Configuration settings to define a scaling policy for the Auto Scaling group that is optimized for game hosting. + * The scaling policy uses the metric `PercentUtilizedGameServers` to maintain a buffer of idle game servers that can immediately accommodate new games and players. + * + * After the Auto Scaling group is created, update this value directly in the Auto Scaling group using the AWS console or APIs. + * + * @default no autoscaling policy settled + */ + readonly autoScalingPolicy?: AutoScalingPolicy; + + /** + * The type of delete to perform. To delete a game server group, specify the DeleteOption + * + * @default SAFE_DELETE + */ + readonly deleteOption?: DeleteOption; + + /** + * Indicates how GameLift FleetIQ balances the use of Spot Instances and On-Demand Instances in the game server group. + * + * @default SPOT_PREFERRED + */ + readonly balancingStrategy?: BalancingStrategy; + + /** + * A list of labels to assign to the new game server group resource. + * Tags are developer-defined key-value pairs. + * Tagging AWS resources is useful for resource management, access management, and cost allocation. + * Once the resource is created, you can use `TagResource`, `UntagResource`, and `ListTagsForResource` to add, remove, and view tags, respectively. + * + * @see https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html + * + * @default {} - no tags + */ + readonly tags?: { [key: string]: string }; +} + +/** + * Creates a GameLift FleetIQ game server group for managing game hosting on a collection of Amazon EC2 instances for game hosting. + * This operation creates the game server group, creates an Auto Scaling group in your AWS account, and establishes a link between the two groups. + * You can view the status of your game server groups in the GameLift console. + * Game server group metrics and events are emitted to Amazon CloudWatch. + * Before creating a new game server group, you must have the following: + * - An Amazon EC2 launch template that specifies how to launch Amazon EC2 instances with your game server build. + * - An IAM role that extends limited access to your AWS account to allow GameLift FleetIQ to create and interact with the Auto Scaling group. + * + * To create a new game server group, specify a unique group name, IAM role and Amazon EC2 launch template, and provide a list of instance types that can be used in the group. + * You must also set initial maximum and minimum limits on the group's instance count. + * You can optionally set an Auto Scaling policy with target tracking based on a GameLift FleetIQ metric. + * + * Once the game server group and corresponding Auto Scaling group are created, you have full access to change the Auto Scaling group's configuration as needed. + * Several properties that are set when creating a game server group, including maximum/minimum size and auto-scaling policy settings, must be updated directly in the Auto Scaling group. + * Keep in mind that some Auto Scaling group properties are periodically updated by GameLift FleetIQ as part of its balancing activities to optimize for availability and cost. + * + * @see https://docs.aws.amazon.com/gamelift/latest/fleetiqguide/gsg-intro.html + * + * @resource AWS::GameLift::GameServerGroup + */ +export class GameServerGroup extends GameServerGroupBase { + + /** + * Import an existing game server group from its attributes. + */ + static fromGameServerGroupAttributes(scope: Construct, id: string, attrs: GameServerGroupAttributes): IGameServerGroup { + if (!attrs.gameServerGroupArn && !attrs.gameServerGroupName) { + throw new Error('Either gameServerGroupName or gameServerGroupArn must be provided in GameServerGroupAttributes'); + } + const gameServerGroupName = attrs.gameServerGroupName ?? + cdk.Stack.of(scope).splitArn(attrs.gameServerGroupArn!, cdk.ArnFormat.SLASH_RESOURCE_NAME).resourceName; + + if (!gameServerGroupName) { + throw new Error(`No game server group name found in ARN: '${attrs.gameServerGroupArn}'`); + } + + const gameServerGroupArn = attrs.gameServerGroupArn ?? cdk.Stack.of(scope).formatArn({ + service: 'gamelift', + resource: 'gameservergroup', + resourceName: attrs.gameServerGroupName, + arnFormat: cdk.ArnFormat.SLASH_RESOURCE_NAME, + }); + + class Import extends GameServerGroupBase { + public readonly gameServerGroupName = gameServerGroupName!; + public readonly gameServerGroupArn = gameServerGroupArn; + public readonly autoScalingGroupArn = attrs.autoScalingGroupArn; + public readonly grantPrincipal = attrs.role ?? new iam.UnknownPrincipal({ resource: this }); + public readonly role = attrs.role; + + constructor(s: Construct, i: string) { + super(s, i, { + environmentFromArn: gameServerGroupArn, + }); + } + } + return new Import(scope, id); + } + + /** + * The name of the game server group + */ + public readonly gameServerGroupName: string; + + /** + * The ARN of the game server group. + */ + public readonly gameServerGroupArn: string; + + /** + * The ARN of the generated AutoScaling group + */ + public readonly autoScalingGroupArn: string; + + /** + * The IAM role that allows Amazon GameLift to access your Amazon EC2 Auto Scaling groups. + */ + public readonly role: iam.IRole; + + /** + * The principal this GameLift game server group is using. + */ + public readonly grantPrincipal: iam.IPrincipal; + + /** + * The VPC network to place the game server group in. + */ + public readonly vpc: ec2.IVpc; + + /** + * The game server group's subnets. + */ + public readonly vpcSubnets?: ec2.SubnetSelection; + + /** + * The set of Amazon EC2 instance types that GameLift FleetIQ can use when balancing and automatically scaling instances in the corresponding Auto Scaling group. + */ + private readonly instanceDefinitions: InstanceDefinition[] = []; + + constructor(scope: Construct, id: string, props: GameServerGroupProps) { + super(scope, id, { + physicalName: props.gameServerGroupName, + }); + + if (!cdk.Token.isUnresolved(props.gameServerGroupName)) { + if (props.gameServerGroupName.length > 128) { + throw new Error(`GameServerGroup name can not be longer than 128 characters but has ${props.gameServerGroupName.length} characters.`); + } + + if (!/^[a-zA-Z0-9-\.]+$/.test(props.gameServerGroupName)) { + throw new Error(`Game server group name ${props.gameServerGroupName} can contain only letters, numbers, hyphens, back slash or dot with no spaces.`); + } + } + + this.vpc = props.vpc; + this.vpcSubnets = props.vpcSubnets ?? { subnetType: ec2.SubnetType.PUBLIC }; + const { subnetIds } = props.vpc.selectSubnets(props.vpcSubnets); + + if (subnetIds.length > 20) { + throw new Error(`No more than 20 subnets are allowed per game server group, given ${subnetIds.length}`); + } + + // Add all instance definitions + if (props.instanceDefinitions.length > 20) { + throw new Error(`No more than 20 instance definitions are allowed per game server group, given ${props.instanceDefinitions.length}`); + } + (props.instanceDefinitions || []).forEach(this.addInternalInstanceDefinition.bind(this)); + + this.role = props.role ?? new iam.Role(this, 'ServiceRole', { + assumedBy: new iam.CompositePrincipal( + new iam.ServicePrincipal('gamelift.amazonaws.com'), + new iam.ServicePrincipal('autoscaling.amazonaws.com')), + managedPolicies: [ + iam.ManagedPolicy.fromAwsManagedPolicyName('GameLiftGameServerGroupPolicy'), + ], + }); + this.grantPrincipal = this.role; + + const resource = new CfnGameServerGroup(this, 'Resource', { + gameServerGroupName: this.physicalName, + autoScalingPolicy: this.parseAutoScalingPolicy(props), + deleteOption: props.deleteOption, + balancingStrategy: props.balancingStrategy, + gameServerProtectionPolicy: props.protectGameServer ? 'FULL_PROTECTION' : 'NO_PROTECTION', + instanceDefinitions: this.parseInstanceDefinitions(), + launchTemplate: this.parseLaunchTemplate(props), + minSize: props.minSize, + maxSize: props.maxSize, + roleArn: this.role.roleArn, + vpcSubnets: subnetIds, + }); + + this.gameServerGroupName = this.getResourceNameAttribute(resource.ref); + this.gameServerGroupArn = this.getResourceArnAttribute(resource.attrGameServerGroupArn, { + service: 'gamelift', + resource: 'gameservergroup', + resourceName: this.physicalName, + arnFormat: cdk.ArnFormat.SLASH_RESOURCE_NAME, + }); + this.autoScalingGroupArn = this.getResourceArnAttribute(resource.attrAutoScalingGroupArn, { + service: 'autoscaling', + resource: 'autoScalingGroup', + resourceName: this.physicalName, + arnFormat: cdk.ArnFormat.COLON_RESOURCE_NAME, + }); + + } + + /** + * Adds an instance definition that GameLift FleetIQ can use when balancing and automatically scaling instances in the corresponding Auto Scaling group + * + * @param instanceType An Amazon EC2 instance type designation. + * @param weight Instance weighting that indicates how much this instance type contributes to the total capacity of a game server group. + */ + public addInstanceDefinition(instanceType: ec2.InstanceType, weight?: number) { + this.addInternalInstanceDefinition({ + instanceType: instanceType, + weight: weight, + }); + } + + /** + * Adds an instance definition that GameLift FleetIQ can use when balancing and automatically scaling instances in the corresponding Auto Scaling group + * + * @param instanceDefinition The instance definition to add + */ + public addInternalInstanceDefinition(instanceDefinition: InstanceDefinition) { + if (this.instanceDefinitions.length == 20) { + throw new Error('No more than 20 instance definitions are allowed per game server group'); + } + + this.instanceDefinitions.push(instanceDefinition); + } + + protected parseLaunchTemplate(props: GameServerGroupProps): CfnGameServerGroup.LaunchTemplateProperty { + return { + launchTemplateId: props.launchTemplate.launchTemplateId, + launchTemplateName: props.launchTemplate.launchTemplateName, + version: props.launchTemplate.versionNumber, + }; + } + + protected parseAutoScalingPolicy(props: GameServerGroupProps): CfnGameServerGroup.AutoScalingPolicyProperty | undefined { + if (!props.autoScalingPolicy) { + return undefined; + } + + return { + estimatedInstanceWarmup: props.autoScalingPolicy.estimatedInstanceWarmup?.toSeconds(), + targetTrackingConfiguration: { + targetValue: props.autoScalingPolicy.targetTrackingConfiguration, + }, + }; + } + + protected parseInstanceDefinitions(): CfnGameServerGroup.InstanceDefinitionProperty[] { + return this.instanceDefinitions.map(parseInstanceDefinition); + + function parseInstanceDefinition(instanceDefinition: InstanceDefinition): CfnGameServerGroup.InstanceDefinitionProperty { + return { + instanceType: instanceDefinition.instanceType.toString(), + weightedCapacity: instanceDefinition.weight?.toString(), + }; + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-gamelift/lib/index.ts b/packages/@aws-cdk/aws-gamelift/lib/index.ts index 13cc0c8eada9c..c71edfbfe2f08 100644 --- a/packages/@aws-cdk/aws-gamelift/lib/index.ts +++ b/packages/@aws-cdk/aws-gamelift/lib/index.ts @@ -1,6 +1,7 @@ export * from './content'; export * from './build'; export * from './script'; +export * from './game-server-group'; // AWS::GameLift CloudFormation Resources: export * from './gamelift.generated'; diff --git a/packages/@aws-cdk/aws-gamelift/test/game-server-group.test.ts b/packages/@aws-cdk/aws-gamelift/test/game-server-group.test.ts new file mode 100644 index 0000000000000..6c57ce76e9ff2 --- /dev/null +++ b/packages/@aws-cdk/aws-gamelift/test/game-server-group.test.ts @@ -0,0 +1,70 @@ + +import { Template } from '@aws-cdk/assertions'; +import * as ec2 from '@aws-cdk/aws-ec2'; +import * as cdk from '@aws-cdk/core'; +import * as gamelift from '../lib'; + +describe('gameservergroup', () => { + + describe('new', () => { + let stack: cdk.Stack; + + beforeEach(() => { + stack = new cdk.Stack(); + }); + + test('default gameservergroup', () => { + const vpc = new ec2.Vpc(stack, 'vpc'); + const launchTemplate = new ec2.LaunchTemplate(stack, 'LaunchTemplte', {}); + new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { + instanceDefinitions: [{ + instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), + }], + vpc: vpc, + launchTemplate: launchTemplate, + gameServerGroupName: 'test-gameservergroup-name', + }); + + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { + AssumeRolePolicyDocument: + { + Statement: + [{ + Action: 'sts:AssumeRole', + Effect: 'Allow', + Principal: { + Service: 'gamelift.amazonaws.com', + }, + }, + { + Action: 'sts:AssumeRole', + Effect: 'Allow', + Principal: { + Service: 'autoscaling.amazonaws.com', + }, + }], + Version: '2012-10-17', + }, + ManagedPolicyArns: [{ + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':iam::aws:policy/GameLiftGameServerGroupPolicy', + ], + ], + }], + }); + + Template.fromStack(stack).hasResource('AWS::GameLift::GameServerGroup', { + Properties: + { + GameServerGroupName: 'test-gameservergroup-name', + }, + }); + }); + }); +}); \ No newline at end of file From b71807c3ee9f823eeb04e6f14860f1ff70cd88d4 Mon Sep 17 00:00:00 2001 From: Steve Houel Date: Thu, 3 Nov 2022 11:26:10 +0100 Subject: [PATCH 2/5] Adding integ-test for GameServerGroup construct --- .../aws-gamelift/lib/game-server-group.ts | 4 +- packages/@aws-cdk/aws-gamelift/package.json | 1 + .../test/game-server-group.test.ts | 327 ++++++- ...efaultTestDeployAssertA631B19B.assets.json | 19 + ...aultTestDeployAssertA631B19B.template.json | 36 + ...aws-gamelift-game-server-group.assets.json | 19 + ...s-gamelift-game-server-group.template.json | 541 +++++++++++ .../cdk.out | 1 + .../integ.json | 12 + .../manifest.json | 261 ++++++ .../tree.json | 876 ++++++++++++++++++ .../test/integ.game-server-group.ts | 38 + 12 files changed, 2129 insertions(+), 6 deletions(-) create mode 100644 packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/GameServerGroupDefaultTestDeployAssertA631B19B.assets.json create mode 100644 packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/GameServerGroupDefaultTestDeployAssertA631B19B.template.json create mode 100644 packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.assets.json create mode 100644 packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.template.json create mode 100644 packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/integ.json create mode 100644 packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/tree.json create mode 100644 packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.ts diff --git a/packages/@aws-cdk/aws-gamelift/lib/game-server-group.ts b/packages/@aws-cdk/aws-gamelift/lib/game-server-group.ts index 11f08bbbd59dd..441149a8096c9 100644 --- a/packages/@aws-cdk/aws-gamelift/lib/game-server-group.ts +++ b/packages/@aws-cdk/aws-gamelift/lib/game-server-group.ts @@ -451,7 +451,7 @@ export class GameServerGroup extends GameServerGroupBase { this.vpc = props.vpc; this.vpcSubnets = props.vpcSubnets ?? { subnetType: ec2.SubnetType.PUBLIC }; - const { subnetIds } = props.vpc.selectSubnets(props.vpcSubnets); + const { subnetIds } = props.vpc.selectSubnets(this.vpcSubnets); if (subnetIds.length > 20) { throw new Error(`No more than 20 subnets are allowed per game server group, given ${subnetIds.length}`); @@ -479,7 +479,7 @@ export class GameServerGroup extends GameServerGroupBase { deleteOption: props.deleteOption, balancingStrategy: props.balancingStrategy, gameServerProtectionPolicy: props.protectGameServer ? 'FULL_PROTECTION' : 'NO_PROTECTION', - instanceDefinitions: this.parseInstanceDefinitions(), + instanceDefinitions: cdk.Lazy.any({ produce: () => this.parseInstanceDefinitions() }), launchTemplate: this.parseLaunchTemplate(props), minSize: props.minSize, maxSize: props.maxSize, diff --git a/packages/@aws-cdk/aws-gamelift/package.json b/packages/@aws-cdk/aws-gamelift/package.json index 6f133644d1d2b..56ba24122e3fd 100644 --- a/packages/@aws-cdk/aws-gamelift/package.json +++ b/packages/@aws-cdk/aws-gamelift/package.json @@ -82,6 +82,7 @@ "devDependencies": { "@aws-cdk/assertions": "0.0.0", "@aws-cdk/cdk-build-tools": "0.0.0", + "@aws-cdk/integ-tests": "0.0.0", "@aws-cdk/integ-runner": "0.0.0", "@aws-cdk/cfn2ts": "0.0.0", "@aws-cdk/pkglint": "0.0.0", diff --git a/packages/@aws-cdk/aws-gamelift/test/game-server-group.test.ts b/packages/@aws-cdk/aws-gamelift/test/game-server-group.test.ts index 6c57ce76e9ff2..fa1fbe63e94b6 100644 --- a/packages/@aws-cdk/aws-gamelift/test/game-server-group.test.ts +++ b/packages/@aws-cdk/aws-gamelift/test/game-server-group.test.ts @@ -1,21 +1,24 @@ -import { Template } from '@aws-cdk/assertions'; +import { Template, Match } from '@aws-cdk/assertions'; import * as ec2 from '@aws-cdk/aws-ec2'; +import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; import * as gamelift from '../lib'; describe('gameservergroup', () => { - describe('new', () => { let stack: cdk.Stack; + let vpc: ec2.Vpc; + let launchTemplate: ec2.LaunchTemplate; beforeEach(() => { stack = new cdk.Stack(); + vpc = new ec2.Vpc(stack, 'vpc'); + launchTemplate = new ec2.LaunchTemplate(stack, 'LaunchTemplte', {}); }); test('default gameservergroup', () => { - const vpc = new ec2.Vpc(stack, 'vpc'); - const launchTemplate = new ec2.LaunchTemplate(stack, 'LaunchTemplte', {}); + new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { instanceDefinitions: [{ instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), @@ -63,8 +66,324 @@ describe('gameservergroup', () => { Properties: { GameServerGroupName: 'test-gameservergroup-name', + GameServerProtectionPolicy: 'NO_PROTECTION', + InstanceDefinitions: [{ InstanceType: 'c5.large' }], + LaunchTemplate: { + LaunchTemplateId: { Ref: 'LaunchTemplte29591DF8' }, + Version: { + 'Fn::GetAtt': [ + 'LaunchTemplte29591DF8', + 'LatestVersionNumber', + ], + }, + }, + RoleArn: { + 'Fn::GetAtt': [ + 'MyGameServerGroupServiceRoleD6701F0B', + 'Arn', + ], + }, + VpcSubnets: [ + { Ref: 'vpcPublicSubnet1Subnet2E65531E' }, + { Ref: 'vpcPublicSubnet2Subnet009B674F' }, + ], + }, + }); + }); + + test('with autoScalingPolicy', () => { + new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { + instanceDefinitions: [{ + instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), + }], + vpc: vpc, + launchTemplate: launchTemplate, + gameServerGroupName: 'test-gameservergroup-name', + autoScalingPolicy: { + targetTrackingConfiguration: 10, + estimatedInstanceWarmup: cdk.Duration.minutes(5), + }, + }); + + Template.fromStack(stack).hasResource('AWS::GameLift::GameServerGroup', { + Properties: + { + GameServerGroupName: 'test-gameservergroup-name', + GameServerProtectionPolicy: 'NO_PROTECTION', + InstanceDefinitions: [{ InstanceType: 'c5.large' }], + LaunchTemplate: { + LaunchTemplateId: { Ref: 'LaunchTemplte29591DF8' }, + Version: { + 'Fn::GetAtt': [ + 'LaunchTemplte29591DF8', + 'LatestVersionNumber', + ], + }, + }, + RoleArn: { + 'Fn::GetAtt': [ + 'MyGameServerGroupServiceRoleD6701F0B', + 'Arn', + ], + }, + VpcSubnets: [ + { Ref: 'vpcPublicSubnet1Subnet2E65531E' }, + { Ref: 'vpcPublicSubnet2Subnet009B674F' }, + ], + AutoScalingPolicy: { + EstimatedInstanceWarmup: 300, + TargetTrackingConfiguration: { + TargetValue: 10, + }, + }, }, }); }); + + test('with an incorrect game server group name length', () => { + let incorrectName = ''; + for (let i = 0; i < 129; i++) { + incorrectName += 'A'; + } + expect(() => new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { + instanceDefinitions: [{ + instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), + }], + vpc: vpc, + launchTemplate: launchTemplate, + gameServerGroupName: incorrectName, + })).toThrow(/GameServerGroup name can not be longer than 128 characters but has 129 characters./); + }); + + test('with an incorrect game server group name format', () => { + let incorrectName = 'test with space'; + expect(() => new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { + instanceDefinitions: [{ + instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), + }], + vpc: vpc, + launchTemplate: launchTemplate, + gameServerGroupName: incorrectName, + })).toThrow(/Game server group name test with space can contain only letters, numbers, hyphens, back slash or dot with no spaces./); + }); + + test('with an incorrect instance definitions list from constructor', () => { + let incorrectInstanceDefinitions: gamelift.InstanceDefinition[] = []; + for (let i = 0; i < 21; i++) { + incorrectInstanceDefinitions.push({ + instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), + }); + } + expect(() => new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { + instanceDefinitions: incorrectInstanceDefinitions, + vpc: vpc, + launchTemplate: launchTemplate, + gameServerGroupName: 'test-name', + })).toThrow(/No more than 20 instance definitions are allowed per game server group, given 21/); + }); + + test('with an incorrect instance definitions list', () => { + let incorrectInstanceDefinitions: gamelift.InstanceDefinition[] = []; + for (let i = 0; i < 20; i++) { + incorrectInstanceDefinitions.push({ + instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), + }); + } + const gameServerGroup = new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { + instanceDefinitions: incorrectInstanceDefinitions, + vpc: vpc, + launchTemplate: launchTemplate, + gameServerGroupName: 'test-name', + }); + expect(() => gameServerGroup.addInstanceDefinition(ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE))) + .toThrow(/No more than 20 instance definitions are allowed per game server group/); + }); + }); + + describe('add instance definition', () => { + let stack: cdk.Stack; + let vpc: ec2.Vpc; + let launchTemplate: ec2.LaunchTemplate; + let gameServerGroup: gamelift.GameServerGroup; + + beforeEach(() => { + stack = new cdk.Stack(); + vpc = new ec2.Vpc(stack, 'vpc'); + launchTemplate = new ec2.LaunchTemplate(stack, 'LaunchTemplte', {}); + gameServerGroup = new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { + instanceDefinitions: [{ + instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), + }], + vpc: vpc, + launchTemplate: launchTemplate, + gameServerGroupName: 'test-gameservergroup-name', + }); + }); + + test('add new instance definition', () => { + // Add a new location + gameServerGroup.addInstanceDefinition(ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE)); + + Template.fromStack(stack).hasResource('AWS::GameLift::GameServerGroup', { + Properties: + { + InstanceDefinitions: [ + { InstanceType: 'c5.large' }, + { InstanceType: 'c4.large' }, + ], + }, + }); + }); + + test('add new instance definition with weight', () => { + // Add a new location + gameServerGroup.addInstanceDefinition(ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE), 10); + + Template.fromStack(stack).hasResource('AWS::GameLift::GameServerGroup', { + Properties: + { + InstanceDefinitions: [ + { InstanceType: 'c5.large' }, + { + InstanceType: 'c4.large', + WeightedCapacity: '10', + }, + ], + }, + }); + }); + }); + + describe('test import methods', () => { + let stack: cdk.Stack; + const gameServerGroupName = 'test-gameservergroup-name'; + const gameServerGroupArn = `arn:aws:gamelift:test-region:123456789012:gameservergroup/${gameServerGroupName}`; + const autoScalingGroupArn = 'arn:aws:autoscaling:test-region:123456789012:autoScalingGroup:test-uuid:autoScalingGroupName/test-name'; + + beforeEach(() => { + const app = new cdk.App(); + stack = new cdk.Stack(app, 'Base', { + env: { account: '111111111111', region: 'stack-region' }, + }); + }); + + test('with required attrs only', () => { + const importedFleet = gamelift.GameServerGroup.fromGameServerGroupAttributes(stack, 'ImportedScript', { gameServerGroupArn, autoScalingGroupArn }); + + expect(importedFleet.autoScalingGroupArn).toEqual(autoScalingGroupArn); + expect(importedFleet.gameServerGroupArn).toEqual(gameServerGroupArn); + expect(importedFleet.gameServerGroupName).toEqual(gameServerGroupName); + expect(importedFleet.env.account).toEqual('123456789012'); + expect(importedFleet.env.region).toEqual('test-region'); + expect(importedFleet.grantPrincipal).toEqual(new iam.UnknownPrincipal({ resource: importedFleet })); + }); + + test('with all attrs', () => { + const role = iam.Role.fromRoleArn(stack, 'Role', 'arn:aws:iam::123456789012:role/TestRole'); + const importedFleet = gamelift.GameServerGroup.fromGameServerGroupAttributes(stack, 'ImportedScript', { gameServerGroupArn, autoScalingGroupArn, role }); + + expect(importedFleet.autoScalingGroupArn).toEqual(autoScalingGroupArn); + expect(importedFleet.gameServerGroupArn).toEqual(gameServerGroupArn); + expect(importedFleet.gameServerGroupName).toEqual(gameServerGroupName); + expect(importedFleet.grantPrincipal).toEqual(role); + }); + + test('with missing attrs', () => { + const role = iam.Role.fromRoleArn(stack, 'Role', 'arn:aws:iam::123456789012:role/TestRole'); + expect(() => gamelift.GameServerGroup.fromGameServerGroupAttributes(stack, 'ImportedScript', { role, autoScalingGroupArn })) + .toThrow(/Either gameServerGroupName or gameServerGroupArn must be provided in GameServerGroupAttributes/); + }); + + test('with invalid ARN', () => { + expect(() => gamelift.GameServerGroup.fromGameServerGroupAttributes(stack, 'ImportedScript', { autoScalingGroupArn, gameServerGroupArn: 'arn:aws:gamelift:test-region:123456789012:gameservergroup' })) + .toThrow(/No game server group name found in ARN: 'arn:aws:gamelift:test-region:123456789012:gameservergroup'/); + }); + + test("the gameServerGroup's region is taken from the ARN", () => { + const importedFleet = gamelift.GameServerGroup.fromGameServerGroupAttributes(stack, 'ImportedScript', { gameServerGroupArn, autoScalingGroupArn }); + expect(importedFleet.env.region).toBe('test-region'); + }); + + test("the gameServerGroup's account is taken from the ARN", () => { + const importedFleet = gamelift.GameServerGroup.fromGameServerGroupAttributes(stack, 'ImportedScript', { gameServerGroupArn, autoScalingGroupArn }); + expect(importedFleet.env.account).toBe('123456789012'); + }); + }); + + describe('metric methods provide a Metric with configured and attached properties', () => { + let stack: cdk.Stack; + let vpc: ec2.Vpc; + let launchTemplate: ec2.LaunchTemplate; + let gameServerGroup: gamelift.GameServerGroup; + + beforeEach(() => { + stack = new cdk.Stack(undefined, undefined, { env: { account: '000000000000', region: 'us-west-1' } }); + vpc = new ec2.Vpc(stack, 'vpc'); + launchTemplate = new ec2.LaunchTemplate(stack, 'LaunchTemplte', {}); + gameServerGroup = new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { + instanceDefinitions: [{ + instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), + }], + vpc: vpc, + launchTemplate: launchTemplate, + gameServerGroupName: 'test-gameservergroup-name', + }); + }); + + test('metric', () => { + const metric = gameServerGroup.metric('AvailableGameServers'); + + expect(metric).toMatchObject({ + account: stack.account, + region: stack.region, + namespace: 'AWS/GameLift', + metricName: 'AvailableGameServers', + dimensions: { + GameServerGroupArn: gameServerGroup.gameServerGroupArn, + }, + }); + }); + }); + + describe('granting access', () => { + let stack: cdk.Stack; + let vpc: ec2.Vpc; + let launchTemplate: ec2.LaunchTemplate; + let gameServerGroup: gamelift.GameServerGroup; + let role: iam.Role; + + beforeEach(() => { + stack = new cdk.Stack(undefined, undefined, { env: { account: '000000000000', region: 'us-west-1' } }); + vpc = new ec2.Vpc(stack, 'vpc'); + role = new iam.Role(stack, 'Role', { + assumedBy: new iam.ServicePrincipal('gamelift.amazonaws.com'), + }); + launchTemplate = new ec2.LaunchTemplate(stack, 'LaunchTemplte', {}); + gameServerGroup = new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { + instanceDefinitions: [{ + instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), + }], + vpc: vpc, + launchTemplate: launchTemplate, + gameServerGroupName: 'test-gameservergroup-name', + role: role, + }); + }); + + test('grant', () => { + gameServerGroup.grant(role, 'gamelift:DescribeGameServerGroup'); + + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { + PolicyDocument: { + Statement: [ + Match.objectLike({ + Action: 'gamelift:DescribeGameServerGroup', + Resource: stack.resolve(gameServerGroup.gameServerGroupArn), + }), + ], + }, + Roles: [stack.resolve(role.roleName)], + }); + }); }); }); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/GameServerGroupDefaultTestDeployAssertA631B19B.assets.json b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/GameServerGroupDefaultTestDeployAssertA631B19B.assets.json new file mode 100644 index 0000000000000..f7fa24e781380 --- /dev/null +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/GameServerGroupDefaultTestDeployAssertA631B19B.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "GameServerGroupDefaultTestDeployAssertA631B19B.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/GameServerGroupDefaultTestDeployAssertA631B19B.template.json b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/GameServerGroupDefaultTestDeployAssertA631B19B.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/GameServerGroupDefaultTestDeployAssertA631B19B.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.assets.json b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.assets.json new file mode 100644 index 0000000000000..3f082783f32bf --- /dev/null +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "1a74a356fdf93b28d3031ef4b2b5ee227f465b60ab8b0744e8e343a71014097b": { + "source": { + "path": "aws-gamelift-game-server-group.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "1a74a356fdf93b28d3031ef4b2b5ee227f465b60ab8b0744e8e343a71014097b.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.template.json b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.template.json new file mode 100644 index 0000000000000..04072698b93aa --- /dev/null +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.template.json @@ -0,0 +1,541 @@ +{ + "Resources": { + "Vpc8378EB38": { + "Type": "AWS::EC2::VPC", + "Properties": { + "CidrBlock": "10.0.0.0/16", + "EnableDnsHostnames": true, + "EnableDnsSupport": true, + "InstanceTenancy": "default", + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc" + } + ] + } + }, + "VpcPublicSubnet1Subnet5C2D37C4": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" + }, + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.0.0/18", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" + } + ] + } + }, + "VpcPublicSubnet1RouteTable6C95E38E": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" + } + ] + } + }, + "VpcPublicSubnet1RouteTableAssociation97140677": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" + }, + "SubnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + } + } + }, + "VpcPublicSubnet1DefaultRoute3DA9E72A": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VpcIGWD7BA715C" + } + }, + "DependsOn": [ + "VpcVPCGWBF912B6E" + ] + }, + "VpcPublicSubnet1EIPD7E02669": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" + } + ] + } + }, + "VpcPublicSubnet1NATGateway4D7517AA": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "SubnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + }, + "AllocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet1EIPD7E02669", + "AllocationId" + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" + } + ] + }, + "DependsOn": [ + "VpcPublicSubnet1DefaultRoute3DA9E72A", + "VpcPublicSubnet1RouteTableAssociation97140677" + ] + }, + "VpcPublicSubnet2Subnet691E08A3": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" + }, + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.64.0/18", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" + } + ] + } + }, + "VpcPublicSubnet2RouteTable94F7E489": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" + } + ] + } + }, + "VpcPublicSubnet2RouteTableAssociationDD5762D8": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" + }, + "SubnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + } + } + }, + "VpcPublicSubnet2DefaultRoute97F91067": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VpcIGWD7BA715C" + } + }, + "DependsOn": [ + "VpcVPCGWBF912B6E" + ] + }, + "VpcPublicSubnet2EIP3C605A87": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" + } + ] + } + }, + "VpcPublicSubnet2NATGateway9182C01D": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "SubnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + }, + "AllocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet2EIP3C605A87", + "AllocationId" + ] + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" + } + ] + }, + "DependsOn": [ + "VpcPublicSubnet2DefaultRoute97F91067", + "VpcPublicSubnet2RouteTableAssociationDD5762D8" + ] + }, + "VpcPrivateSubnet1Subnet536B997A": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" + }, + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.128.0/18", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1" + } + ] + } + }, + "VpcPrivateSubnet1RouteTableB2C5B500": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1" + } + ] + } + }, + "VpcPrivateSubnet1RouteTableAssociation70C59FA6": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" + }, + "SubnetId": { + "Ref": "VpcPrivateSubnet1Subnet536B997A" + } + } + }, + "VpcPrivateSubnet1DefaultRouteBE02A9ED": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VpcPublicSubnet1NATGateway4D7517AA" + } + } + }, + "VpcPrivateSubnet2Subnet3788AAA1": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" + }, + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.192.0/18", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2" + } + ] + } + }, + "VpcPrivateSubnet2RouteTableA678073B": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2" + } + ] + } + }, + "VpcPrivateSubnet2RouteTableAssociationA89CAD56": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" + }, + "SubnetId": { + "Ref": "VpcPrivateSubnet2Subnet3788AAA1" + } + } + }, + "VpcPrivateSubnet2DefaultRoute060D2087": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VpcPublicSubnet2NATGateway9182C01D" + } + } + }, + "VpcIGWD7BA715C": { + "Type": "AWS::EC2::InternetGateway", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc" + } + ] + } + }, + "VpcVPCGWBF912B6E": { + "Type": "AWS::EC2::VPCGatewayAttachment", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" + }, + "InternetGatewayId": { + "Ref": "VpcIGWD7BA715C" + } + } + }, + "LaunchTemplate04EC5460": { + "Type": "AWS::EC2::LaunchTemplate", + "Properties": { + "LaunchTemplateData": { + "TagSpecifications": [ + { + "ResourceType": "instance", + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/LaunchTemplate" + } + ] + }, + { + "ResourceType": "volume", + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/LaunchTemplate" + } + ] + } + ] + }, + "TagSpecifications": [ + { + "ResourceType": "launch-template", + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/LaunchTemplate" + } + ] + } + ] + } + }, + "MyGameServerGroupServiceRoleD6701F0B": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": [ + "autoscaling.amazonaws.com", + "gamelift.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/GameLiftGameServerGroupPolicy" + ] + ] + } + ] + } + }, + "MyGameServerGroupA706FA3E": { + "Type": "AWS::GameLift::GameServerGroup", + "Properties": { + "GameServerGroupName": "test-gameservergroup-name", + "InstanceDefinitions": [ + { + "InstanceType": "c5.large" + }, + { + "InstanceType": "c4.large" + } + ], + "LaunchTemplate": { + "LaunchTemplateId": { + "Ref": "LaunchTemplate04EC5460" + }, + "Version": { + "Fn::GetAtt": [ + "LaunchTemplate04EC5460", + "LatestVersionNumber" + ] + } + }, + "RoleArn": { + "Fn::GetAtt": [ + "MyGameServerGroupServiceRoleD6701F0B", + "Arn" + ] + }, + "GameServerProtectionPolicy": "NO_PROTECTION", + "VpcSubnets": [ + { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + }, + { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + } + ] + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } + } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/cdk.out b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/cdk.out new file mode 100644 index 0000000000000..8ecc185e9dbee --- /dev/null +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"21.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/integ.json b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/integ.json new file mode 100644 index 0000000000000..7dfb7ecf345df --- /dev/null +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "21.0.0", + "testCases": { + "GameServerGroup/DefaultTest": { + "stacks": [ + "aws-gamelift-game-server-group" + ], + "assertionStack": "GameServerGroup/DefaultTest/DeployAssert", + "assertionStackName": "GameServerGroupDefaultTestDeployAssertA631B19B" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/manifest.json b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/manifest.json new file mode 100644 index 0000000000000..c7d4fc3ddfa1d --- /dev/null +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/manifest.json @@ -0,0 +1,261 @@ +{ + "version": "21.0.0", + "artifacts": { + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + }, + "aws-gamelift-game-server-group.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "aws-gamelift-game-server-group.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "aws-gamelift-game-server-group": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "aws-gamelift-game-server-group.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/1a74a356fdf93b28d3031ef4b2b5ee227f465b60ab8b0744e8e343a71014097b.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "aws-gamelift-game-server-group.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "aws-gamelift-game-server-group.assets" + ], + "metadata": { + "/aws-gamelift-game-server-group/Vpc/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Vpc8378EB38" + } + ], + "/aws-gamelift-game-server-group/Vpc/PublicSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1Subnet5C2D37C4" + } + ], + "/aws-gamelift-game-server-group/Vpc/PublicSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1RouteTable6C95E38E" + } + ], + "/aws-gamelift-game-server-group/Vpc/PublicSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1RouteTableAssociation97140677" + } + ], + "/aws-gamelift-game-server-group/Vpc/PublicSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1DefaultRoute3DA9E72A" + } + ], + "/aws-gamelift-game-server-group/Vpc/PublicSubnet1/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1EIPD7E02669" + } + ], + "/aws-gamelift-game-server-group/Vpc/PublicSubnet1/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1NATGateway4D7517AA" + } + ], + "/aws-gamelift-game-server-group/Vpc/PublicSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2Subnet691E08A3" + } + ], + "/aws-gamelift-game-server-group/Vpc/PublicSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2RouteTable94F7E489" + } + ], + "/aws-gamelift-game-server-group/Vpc/PublicSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2RouteTableAssociationDD5762D8" + } + ], + "/aws-gamelift-game-server-group/Vpc/PublicSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2DefaultRoute97F91067" + } + ], + "/aws-gamelift-game-server-group/Vpc/PublicSubnet2/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2EIP3C605A87" + } + ], + "/aws-gamelift-game-server-group/Vpc/PublicSubnet2/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2NATGateway9182C01D" + } + ], + "/aws-gamelift-game-server-group/Vpc/PrivateSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet1Subnet536B997A" + } + ], + "/aws-gamelift-game-server-group/Vpc/PrivateSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet1RouteTableB2C5B500" + } + ], + "/aws-gamelift-game-server-group/Vpc/PrivateSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet1RouteTableAssociation70C59FA6" + } + ], + "/aws-gamelift-game-server-group/Vpc/PrivateSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet1DefaultRouteBE02A9ED" + } + ], + "/aws-gamelift-game-server-group/Vpc/PrivateSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet2Subnet3788AAA1" + } + ], + "/aws-gamelift-game-server-group/Vpc/PrivateSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet2RouteTableA678073B" + } + ], + "/aws-gamelift-game-server-group/Vpc/PrivateSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet2RouteTableAssociationA89CAD56" + } + ], + "/aws-gamelift-game-server-group/Vpc/PrivateSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet2DefaultRoute060D2087" + } + ], + "/aws-gamelift-game-server-group/Vpc/IGW": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcIGWD7BA715C" + } + ], + "/aws-gamelift-game-server-group/Vpc/VPCGW": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcVPCGWBF912B6E" + } + ], + "/aws-gamelift-game-server-group/LaunchTemplate/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "LaunchTemplate04EC5460" + } + ], + "/aws-gamelift-game-server-group/MyGameServerGroup/ServiceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyGameServerGroupServiceRoleD6701F0B" + } + ], + "/aws-gamelift-game-server-group/MyGameServerGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyGameServerGroupA706FA3E" + } + ], + "/aws-gamelift-game-server-group/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/aws-gamelift-game-server-group/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "aws-gamelift-game-server-group" + }, + "GameServerGroupDefaultTestDeployAssertA631B19B.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "GameServerGroupDefaultTestDeployAssertA631B19B.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "GameServerGroupDefaultTestDeployAssertA631B19B": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "GameServerGroupDefaultTestDeployAssertA631B19B.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "GameServerGroupDefaultTestDeployAssertA631B19B.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "GameServerGroupDefaultTestDeployAssertA631B19B.assets" + ], + "metadata": { + "/GameServerGroup/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/GameServerGroup/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "GameServerGroup/DefaultTest/DeployAssert" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/tree.json b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/tree.json new file mode 100644 index 0000000000000..f6bf7a40ea0e6 --- /dev/null +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/tree.json @@ -0,0 +1,876 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.140" + } + }, + "aws-gamelift-game-server-group": { + "id": "aws-gamelift-game-server-group", + "path": "aws-gamelift-game-server-group", + "children": { + "Vpc": { + "id": "Vpc", + "path": "aws-gamelift-game-server-group/Vpc", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-gamelift-game-server-group/Vpc/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::VPC", + "aws:cdk:cloudformation:props": { + "cidrBlock": "10.0.0.0/16", + "enableDnsHostnames": true, + "enableDnsSupport": true, + "instanceTenancy": "default", + "tags": [ + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnVPC", + "version": "0.0.0" + } + }, + "PublicSubnet1": { + "id": "PublicSubnet1", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet1/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "Vpc8378EB38" + }, + "availabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.0.0/18", + "mapPublicIpOnLaunch": true, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Public" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Public" + }, + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet1/Acl", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "Vpc8378EB38" + }, + "tags": [ + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" + }, + "subnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" + }, + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "VpcIGWD7BA715C" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRoute", + "version": "0.0.0" + } + }, + "EIP": { + "id": "EIP", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet1/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnEIP", + "version": "0.0.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet1/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "subnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + }, + "allocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet1EIPD7E02669", + "AllocationId" + ] + }, + "tags": [ + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnNatGateway", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.PublicSubnet", + "version": "0.0.0" + } + }, + "PublicSubnet2": { + "id": "PublicSubnet2", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet2/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "Vpc8378EB38" + }, + "availabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.64.0/18", + "mapPublicIpOnLaunch": true, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Public" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Public" + }, + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet2/Acl", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "Vpc8378EB38" + }, + "tags": [ + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" + }, + "subnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" + }, + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "VpcIGWD7BA715C" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRoute", + "version": "0.0.0" + } + }, + "EIP": { + "id": "EIP", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet2/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnEIP", + "version": "0.0.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "aws-gamelift-game-server-group/Vpc/PublicSubnet2/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "subnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + }, + "allocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet2EIP3C605A87", + "AllocationId" + ] + }, + "tags": [ + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnNatGateway", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.PublicSubnet", + "version": "0.0.0" + } + }, + "PrivateSubnet1": { + "id": "PrivateSubnet1", + "path": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "Vpc8378EB38" + }, + "availabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.128.0/18", + "mapPublicIpOnLaunch": false, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Private" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Private" + }, + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1/Acl", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "Vpc8378EB38" + }, + "tags": [ + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" + }, + "subnetId": { + "Ref": "VpcPrivateSubnet1Subnet536B997A" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" + }, + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "VpcPublicSubnet1NATGateway4D7517AA" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRoute", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.PrivateSubnet", + "version": "0.0.0" + } + }, + "PrivateSubnet2": { + "id": "PrivateSubnet2", + "path": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "Vpc8378EB38" + }, + "availabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.192.0/18", + "mapPublicIpOnLaunch": false, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Private" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Private" + }, + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2/Acl", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "Vpc8378EB38" + }, + "tags": [ + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" + }, + "subnetId": { + "Ref": "VpcPrivateSubnet2Subnet3788AAA1" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" + }, + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "VpcPublicSubnet2NATGateway9182C01D" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnRoute", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.PrivateSubnet", + "version": "0.0.0" + } + }, + "IGW": { + "id": "IGW", + "path": "aws-gamelift-game-server-group/Vpc/IGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::InternetGateway", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-gamelift-game-server-group/Vpc" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnInternetGateway", + "version": "0.0.0" + } + }, + "VPCGW": { + "id": "VPCGW", + "path": "aws-gamelift-game-server-group/Vpc/VPCGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::VPCGatewayAttachment", + "aws:cdk:cloudformation:props": { + "vpcId": { + "Ref": "Vpc8378EB38" + }, + "internetGatewayId": { + "Ref": "VpcIGWD7BA715C" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnVPCGatewayAttachment", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.Vpc", + "version": "0.0.0" + } + }, + "LaunchTemplate": { + "id": "LaunchTemplate", + "path": "aws-gamelift-game-server-group/LaunchTemplate", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-gamelift-game-server-group/LaunchTemplate/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::LaunchTemplate", + "aws:cdk:cloudformation:props": { + "launchTemplateData": { + "tagSpecifications": [ + { + "resourceType": "instance", + "tags": [ + { + "key": "Name", + "value": "aws-gamelift-game-server-group/LaunchTemplate" + } + ] + }, + { + "resourceType": "volume", + "tags": [ + { + "key": "Name", + "value": "aws-gamelift-game-server-group/LaunchTemplate" + } + ] + } + ] + }, + "tagSpecifications": [ + { + "resourceType": "launch-template", + "tags": [ + { + "key": "Name", + "value": "aws-gamelift-game-server-group/LaunchTemplate" + } + ] + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.CfnLaunchTemplate", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-ec2.LaunchTemplate", + "version": "0.0.0" + } + }, + "MyGameServerGroup": { + "id": "MyGameServerGroup", + "path": "aws-gamelift-game-server-group/MyGameServerGroup", + "children": { + "ServiceRole": { + "id": "ServiceRole", + "path": "aws-gamelift-game-server-group/MyGameServerGroup/ServiceRole", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-gamelift-game-server-group/MyGameServerGroup/ServiceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": [ + "autoscaling.amazonaws.com", + "gamelift.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "managedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/GameLiftGameServerGroupPolicy" + ] + ] + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-gamelift-game-server-group/MyGameServerGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::GameLift::GameServerGroup", + "aws:cdk:cloudformation:props": { + "gameServerGroupName": "test-gameservergroup-name", + "instanceDefinitions": [ + { + "instanceType": "c5.large" + }, + { + "instanceType": "c4.large" + } + ], + "launchTemplate": { + "launchTemplateId": { + "Ref": "LaunchTemplate04EC5460" + }, + "version": { + "Fn::GetAtt": [ + "LaunchTemplate04EC5460", + "LatestVersionNumber" + ] + } + }, + "roleArn": { + "Fn::GetAtt": [ + "MyGameServerGroupServiceRoleD6701F0B", + "Arn" + ] + }, + "gameServerProtectionPolicy": "NO_PROTECTION", + "vpcSubnets": [ + { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + }, + { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-gamelift.CfnGameServerGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-gamelift.GameServerGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + }, + "GameServerGroup": { + "id": "GameServerGroup", + "path": "GameServerGroup", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "GameServerGroup/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "GameServerGroup/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.140" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "GameServerGroup/DefaultTest/DeployAssert", + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTest", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.ts b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.ts new file mode 100644 index 0000000000000..370221c9adf1a --- /dev/null +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.ts @@ -0,0 +1,38 @@ +import * as ec2 from '@aws-cdk/aws-ec2'; +import * as cdk from '@aws-cdk/core'; +import { IntegTest } from '@aws-cdk/integ-tests'; +import { Construct } from 'constructs'; +import * as gamelift from '../lib'; + +class TestStack extends cdk.Stack { + constructor(scope: Construct, id: string, props?: cdk.StackProps) { + super(scope, id, props); + + // Create default VPC + const vpc = new ec2.Vpc(this, 'Vpc'); + + //Create default launch template + const launchTemplate = new ec2.LaunchTemplate(this, 'LaunchTemplate', {}); + + new gamelift.GameServerGroup(this, 'MyGameServerGroup', { + instanceDefinitions: [{ + instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), + }, + { + instanceType: ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE), + }], + vpc: vpc, + launchTemplate: launchTemplate, + gameServerGroupName: 'test-gameservergroup-name', + }); + } +} + +// Beginning of the test suite +const app = new cdk.App(); +const stack = new TestStack(app, 'aws-gamelift-game-server-group'); +new IntegTest(app, 'GameServerGroup', { + testCases: [stack], +}); + +app.synth(); From 77192008681df99c84bb4bd92a22f58e0d4ca373 Mon Sep 17 00:00:00 2001 From: Steve Houel Date: Thu, 3 Nov 2022 11:57:36 +0100 Subject: [PATCH 3/5] Adding README documentation --- packages/@aws-cdk/aws-gamelift/README.md | 165 ++++++++++++++++++ .../aws-gamelift/rosetta/default.ts-fixture | 3 +- .../test/integ.game-server-group.ts | 1 + 3 files changed, 168 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-gamelift/README.md b/packages/@aws-cdk/aws-gamelift/README.md index 48a572920d223..8a1fb958781d2 100644 --- a/packages/@aws-cdk/aws-gamelift/README.md +++ b/packages/@aws-cdk/aws-gamelift/README.md @@ -109,3 +109,168 @@ new gamelift.Script(this, 'Script', { content: gamelift.Content.fromBucket(bucket, "sample-asset-key") }); ``` + +## 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 + +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 ressource 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 } +}); +``` + +### 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 +thresold 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*. diff --git a/packages/@aws-cdk/aws-gamelift/rosetta/default.ts-fixture b/packages/@aws-cdk/aws-gamelift/rosetta/default.ts-fixture index 4a4c332becb50..a343bb1afbee4 100644 --- a/packages/@aws-cdk/aws-gamelift/rosetta/default.ts-fixture +++ b/packages/@aws-cdk/aws-gamelift/rosetta/default.ts-fixture @@ -3,7 +3,8 @@ import { Construct } from 'constructs'; import { Duration, Size, Stack } from '@aws-cdk/core'; import * as gamelift from '@aws-cdk/aws-gamelift'; import * as s3 from '@aws-cdk/aws-s3'; -import * as kms from '@aws-cdk/aws-kms'; +import * as ec2 from '@aws-cdk/aws-ec2'; +import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; import * as iam from '@aws-cdk/aws-iam'; import * as path from 'path'; diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.ts b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.ts index 370221c9adf1a..2dcc5077cf946 100644 --- a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.ts +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.ts @@ -36,3 +36,4 @@ new IntegTest(app, 'GameServerGroup', { }); app.synth(); + From b9c4bb89d7f1edf6add88bb909fc704c356a7a80 Mon Sep 17 00:00:00 2001 From: Steve Houel Date: Thu, 3 Nov 2022 14:32:37 +0100 Subject: [PATCH 4/5] Migrate existing integration test to new integ-tests version --- ...aws-gamelift-game-server-group.assets.json | 4 +- ...s-gamelift-game-server-group.template.json | 964 +++++++++--------- .../manifest.json | 8 +- .../tree.json | 24 +- .../test/integ.game-server-group.ts | 12 +- 5 files changed, 528 insertions(+), 484 deletions(-) diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.assets.json b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.assets.json index 3f082783f32bf..5d2d42f94c1eb 100644 --- a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.assets.json +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.assets.json @@ -1,7 +1,7 @@ { "version": "21.0.0", "files": { - "1a74a356fdf93b28d3031ef4b2b5ee227f465b60ab8b0744e8e343a71014097b": { + "0233f946355da9a29bd7caaf5049caf4cd4e71dfa10d084bd5ff56e547903847": { "source": { "path": "aws-gamelift-game-server-group.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "1a74a356fdf93b28d3031ef4b2b5ee227f465b60ab8b0744e8e343a71014097b.json", + "objectKey": "0233f946355da9a29bd7caaf5049caf4cd4e71dfa10d084bd5ff56e547903847.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.template.json b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.template.json index 04072698b93aa..451002608b0dc 100644 --- a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.template.json +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/aws-gamelift-game-server-group.template.json @@ -1,541 +1,551 @@ { - "Resources": { - "Vpc8378EB38": { - "Type": "AWS::EC2::VPC", - "Properties": { - "CidrBlock": "10.0.0.0/16", - "EnableDnsHostnames": true, - "EnableDnsSupport": true, - "InstanceTenancy": "default", - "Tags": [ - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc" - } - ] + "Resources": { + "Vpc8378EB38": { + "Type": "AWS::EC2::VPC", + "Properties": { + "CidrBlock": "10.0.0.0/16", + "EnableDnsHostnames": true, + "EnableDnsSupport": true, + "InstanceTenancy": "default", + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc" } + ] + } + }, + "VpcPublicSubnet1Subnet5C2D37C4": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" }, - "VpcPublicSubnet1Subnet5C2D37C4": { - "Type": "AWS::EC2::Subnet", - "Properties": { - "VpcId": { - "Ref": "Vpc8378EB38" - }, - "AvailabilityZone": { - "Fn::Select": [ - 0, - { - "Fn::GetAZs": "" - } - ] - }, - "CidrBlock": "10.0.0.0/18", - "MapPublicIpOnLaunch": true, - "Tags": [ - { - "Key": "aws-cdk:subnet-name", - "Value": "Public" - }, - { - "Key": "aws-cdk:subnet-type", - "Value": "Public" - }, - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" - } - ] + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.0.0/18", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" } + ] + } + }, + "VpcPublicSubnet1RouteTable6C95E38E": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" }, - "VpcPublicSubnet1RouteTable6C95E38E": { - "Type": "AWS::EC2::RouteTable", - "Properties": { - "VpcId": { - "Ref": "Vpc8378EB38" - }, - "Tags": [ - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" - } - ] + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" } + ] + } + }, + "VpcPublicSubnet1RouteTableAssociation97140677": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" }, - "VpcPublicSubnet1RouteTableAssociation97140677": { - "Type": "AWS::EC2::SubnetRouteTableAssociation", - "Properties": { - "RouteTableId": { - "Ref": "VpcPublicSubnet1RouteTable6C95E38E" - }, - "SubnetId": { - "Ref": "VpcPublicSubnet1Subnet5C2D37C4" - } + "SubnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + } + } + }, + "VpcPublicSubnet1DefaultRoute3DA9E72A": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VpcIGWD7BA715C" + } + }, + "DependsOn": [ + "VpcVPCGWBF912B6E" + ] + }, + "VpcPublicSubnet1EIPD7E02669": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" } + ] + } + }, + "VpcPublicSubnet1NATGateway4D7517AA": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "SubnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" }, - "VpcPublicSubnet1DefaultRoute3DA9E72A": { - "Type": "AWS::EC2::Route", - "Properties": { - "RouteTableId": { - "Ref": "VpcPublicSubnet1RouteTable6C95E38E" - }, - "DestinationCidrBlock": "0.0.0.0/0", - "GatewayId": { - "Ref": "VpcIGWD7BA715C" - } - }, - "DependsOn": [ - "VpcVPCGWBF912B6E" + "AllocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet1EIPD7E02669", + "AllocationId" ] }, - "VpcPublicSubnet1EIPD7E02669": { - "Type": "AWS::EC2::EIP", - "Properties": { - "Domain": "vpc", - "Tags": [ - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" - } - ] + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" } + ] + }, + "DependsOn": [ + "VpcPublicSubnet1DefaultRoute3DA9E72A", + "VpcPublicSubnet1RouteTableAssociation97140677" + ] + }, + "VpcPublicSubnet2Subnet691E08A3": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" }, - "VpcPublicSubnet1NATGateway4D7517AA": { - "Type": "AWS::EC2::NatGateway", - "Properties": { - "SubnetId": { - "Ref": "VpcPublicSubnet1Subnet5C2D37C4" - }, - "AllocationId": { - "Fn::GetAtt": [ - "VpcPublicSubnet1EIPD7E02669", - "AllocationId" - ] - }, - "Tags": [ - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet1" - } - ] - }, - "DependsOn": [ - "VpcPublicSubnet1DefaultRoute3DA9E72A", - "VpcPublicSubnet1RouteTableAssociation97140677" + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } ] }, - "VpcPublicSubnet2Subnet691E08A3": { - "Type": "AWS::EC2::Subnet", - "Properties": { - "VpcId": { - "Ref": "Vpc8378EB38" - }, - "AvailabilityZone": { - "Fn::Select": [ - 1, - { - "Fn::GetAZs": "" - } - ] - }, - "CidrBlock": "10.0.64.0/18", - "MapPublicIpOnLaunch": true, - "Tags": [ - { - "Key": "aws-cdk:subnet-name", - "Value": "Public" - }, - { - "Key": "aws-cdk:subnet-type", - "Value": "Public" - }, - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" - } - ] + "CidrBlock": "10.0.64.0/18", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" } + ] + } + }, + "VpcPublicSubnet2RouteTable94F7E489": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" }, - "VpcPublicSubnet2RouteTable94F7E489": { - "Type": "AWS::EC2::RouteTable", - "Properties": { - "VpcId": { - "Ref": "Vpc8378EB38" - }, - "Tags": [ - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" - } - ] + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" } + ] + } + }, + "VpcPublicSubnet2RouteTableAssociationDD5762D8": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" }, - "VpcPublicSubnet2RouteTableAssociationDD5762D8": { - "Type": "AWS::EC2::SubnetRouteTableAssociation", - "Properties": { - "RouteTableId": { - "Ref": "VpcPublicSubnet2RouteTable94F7E489" - }, - "SubnetId": { - "Ref": "VpcPublicSubnet2Subnet691E08A3" - } + "SubnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + } + } + }, + "VpcPublicSubnet2DefaultRoute97F91067": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VpcIGWD7BA715C" + } + }, + "DependsOn": [ + "VpcVPCGWBF912B6E" + ] + }, + "VpcPublicSubnet2EIP3C605A87": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" } + ] + } + }, + "VpcPublicSubnet2NATGateway9182C01D": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "SubnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" }, - "VpcPublicSubnet2DefaultRoute97F91067": { - "Type": "AWS::EC2::Route", - "Properties": { - "RouteTableId": { - "Ref": "VpcPublicSubnet2RouteTable94F7E489" - }, - "DestinationCidrBlock": "0.0.0.0/0", - "GatewayId": { - "Ref": "VpcIGWD7BA715C" - } - }, - "DependsOn": [ - "VpcVPCGWBF912B6E" + "AllocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet2EIP3C605A87", + "AllocationId" ] }, - "VpcPublicSubnet2EIP3C605A87": { - "Type": "AWS::EC2::EIP", - "Properties": { - "Domain": "vpc", - "Tags": [ - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" - } - ] + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" } + ] + }, + "DependsOn": [ + "VpcPublicSubnet2DefaultRoute97F91067", + "VpcPublicSubnet2RouteTableAssociationDD5762D8" + ] + }, + "VpcPrivateSubnet1Subnet536B997A": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" }, - "VpcPublicSubnet2NATGateway9182C01D": { - "Type": "AWS::EC2::NatGateway", - "Properties": { - "SubnetId": { - "Ref": "VpcPublicSubnet2Subnet691E08A3" - }, - "AllocationId": { - "Fn::GetAtt": [ - "VpcPublicSubnet2EIP3C605A87", - "AllocationId" - ] - }, - "Tags": [ - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc/PublicSubnet2" - } - ] - }, - "DependsOn": [ - "VpcPublicSubnet2DefaultRoute97F91067", - "VpcPublicSubnet2RouteTableAssociationDD5762D8" + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } ] }, - "VpcPrivateSubnet1Subnet536B997A": { - "Type": "AWS::EC2::Subnet", - "Properties": { - "VpcId": { - "Ref": "Vpc8378EB38" - }, - "AvailabilityZone": { - "Fn::Select": [ - 0, - { - "Fn::GetAZs": "" - } - ] - }, - "CidrBlock": "10.0.128.0/18", - "MapPublicIpOnLaunch": false, - "Tags": [ - { - "Key": "aws-cdk:subnet-name", - "Value": "Private" - }, - { - "Key": "aws-cdk:subnet-type", - "Value": "Private" - }, - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1" - } - ] + "CidrBlock": "10.0.128.0/18", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1" } + ] + } + }, + "VpcPrivateSubnet1RouteTableB2C5B500": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" }, - "VpcPrivateSubnet1RouteTableB2C5B500": { - "Type": "AWS::EC2::RouteTable", - "Properties": { - "VpcId": { - "Ref": "Vpc8378EB38" - }, - "Tags": [ - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1" - } - ] + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet1" } + ] + } + }, + "VpcPrivateSubnet1RouteTableAssociation70C59FA6": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" }, - "VpcPrivateSubnet1RouteTableAssociation70C59FA6": { - "Type": "AWS::EC2::SubnetRouteTableAssociation", - "Properties": { - "RouteTableId": { - "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" - }, - "SubnetId": { - "Ref": "VpcPrivateSubnet1Subnet536B997A" - } - } + "SubnetId": { + "Ref": "VpcPrivateSubnet1Subnet536B997A" + } + } + }, + "VpcPrivateSubnet1DefaultRouteBE02A9ED": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" }, - "VpcPrivateSubnet1DefaultRouteBE02A9ED": { - "Type": "AWS::EC2::Route", - "Properties": { - "RouteTableId": { - "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" - }, - "DestinationCidrBlock": "0.0.0.0/0", - "NatGatewayId": { - "Ref": "VpcPublicSubnet1NATGateway4D7517AA" + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VpcPublicSubnet1NATGateway4D7517AA" + } + } + }, + "VpcPrivateSubnet2Subnet3788AAA1": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" + }, + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" } - } + ] }, - "VpcPrivateSubnet2Subnet3788AAA1": { - "Type": "AWS::EC2::Subnet", - "Properties": { - "VpcId": { - "Ref": "Vpc8378EB38" - }, - "AvailabilityZone": { - "Fn::Select": [ - 1, - { - "Fn::GetAZs": "" - } - ] - }, - "CidrBlock": "10.0.192.0/18", - "MapPublicIpOnLaunch": false, - "Tags": [ - { - "Key": "aws-cdk:subnet-name", - "Value": "Private" - }, - { - "Key": "aws-cdk:subnet-type", - "Value": "Private" - }, - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2" - } - ] + "CidrBlock": "10.0.192.0/18", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2" } + ] + } + }, + "VpcPrivateSubnet2RouteTableA678073B": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" }, - "VpcPrivateSubnet2RouteTableA678073B": { - "Type": "AWS::EC2::RouteTable", - "Properties": { - "VpcId": { - "Ref": "Vpc8378EB38" - }, - "Tags": [ - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2" - } - ] + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc/PrivateSubnet2" } + ] + } + }, + "VpcPrivateSubnet2RouteTableAssociationA89CAD56": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" }, - "VpcPrivateSubnet2RouteTableAssociationA89CAD56": { - "Type": "AWS::EC2::SubnetRouteTableAssociation", - "Properties": { - "RouteTableId": { - "Ref": "VpcPrivateSubnet2RouteTableA678073B" - }, - "SubnetId": { - "Ref": "VpcPrivateSubnet2Subnet3788AAA1" - } + "SubnetId": { + "Ref": "VpcPrivateSubnet2Subnet3788AAA1" + } + } + }, + "VpcPrivateSubnet2DefaultRoute060D2087": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VpcPublicSubnet2NATGateway9182C01D" + } + } + }, + "VpcIGWD7BA715C": { + "Type": "AWS::EC2::InternetGateway", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/Vpc" } + ] + } + }, + "VpcVPCGWBF912B6E": { + "Type": "AWS::EC2::VPCGatewayAttachment", + "Properties": { + "VpcId": { + "Ref": "Vpc8378EB38" }, - "VpcPrivateSubnet2DefaultRoute060D2087": { - "Type": "AWS::EC2::Route", - "Properties": { - "RouteTableId": { - "Ref": "VpcPrivateSubnet2RouteTableA678073B" + "InternetGatewayId": { + "Ref": "VpcIGWD7BA715C" + } + } + }, + "LaunchTemplate04EC5460": { + "Type": "AWS::EC2::LaunchTemplate", + "Properties": { + "LaunchTemplateData": { + "ImageId": { + "Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter" + }, + "TagSpecifications": [ + { + "ResourceType": "instance", + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/LaunchTemplate" + } + ] }, - "DestinationCidrBlock": "0.0.0.0/0", - "NatGatewayId": { - "Ref": "VpcPublicSubnet2NATGateway9182C01D" + { + "ResourceType": "volume", + "Tags": [ + { + "Key": "Name", + "Value": "aws-gamelift-game-server-group/LaunchTemplate" + } + ] } - } + ] }, - "VpcIGWD7BA715C": { - "Type": "AWS::EC2::InternetGateway", - "Properties": { + "TagSpecifications": [ + { + "ResourceType": "launch-template", "Tags": [ { "Key": "Name", - "Value": "aws-gamelift-game-server-group/Vpc" + "Value": "aws-gamelift-game-server-group/LaunchTemplate" } ] } - }, - "VpcVPCGWBF912B6E": { - "Type": "AWS::EC2::VPCGatewayAttachment", - "Properties": { - "VpcId": { - "Ref": "Vpc8378EB38" - }, - "InternetGatewayId": { - "Ref": "VpcIGWD7BA715C" + ] + } + }, + "MyGameServerGroupServiceRoleD6701F0B": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": [ + "autoscaling.amazonaws.com", + "gamelift.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" }, - "LaunchTemplate04EC5460": { - "Type": "AWS::EC2::LaunchTemplate", - "Properties": { - "LaunchTemplateData": { - "TagSpecifications": [ + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", { - "ResourceType": "instance", - "Tags": [ - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/LaunchTemplate" - } - ] + "Ref": "AWS::Partition" }, - { - "ResourceType": "volume", - "Tags": [ - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/LaunchTemplate" - } - ] - } + ":iam::aws:policy/GameLiftGameServerGroupPolicy" ] - }, - "TagSpecifications": [ - { - "ResourceType": "launch-template", - "Tags": [ - { - "Key": "Name", - "Value": "aws-gamelift-game-server-group/LaunchTemplate" - } - ] - } ] } - }, - "MyGameServerGroupServiceRoleD6701F0B": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": [ - "autoscaling.amazonaws.com", - "gamelift.amazonaws.com" - ] - } - } - ], - "Version": "2012-10-17" - }, - "ManagedPolicyArns": [ - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":iam::aws:policy/GameLiftGameServerGroupPolicy" - ] - ] - } + ] + } + }, + "MyGameServerGroupA706FA3E": { + "Type": "AWS::GameLift::GameServerGroup", + "Properties": { + "GameServerGroupName": "test-gameservergroup-name", + "InstanceDefinitions": [ + { + "InstanceType": "c5.large" + }, + { + "InstanceType": "c4.large" + } + ], + "LaunchTemplate": { + "LaunchTemplateId": { + "Ref": "LaunchTemplate04EC5460" + }, + "Version": { + "Fn::GetAtt": [ + "LaunchTemplate04EC5460", + "LatestVersionNumber" ] } }, - "MyGameServerGroupA706FA3E": { - "Type": "AWS::GameLift::GameServerGroup", - "Properties": { - "GameServerGroupName": "test-gameservergroup-name", - "InstanceDefinitions": [ - { - "InstanceType": "c5.large" - }, - { - "InstanceType": "c4.large" - } - ], - "LaunchTemplate": { - "LaunchTemplateId": { - "Ref": "LaunchTemplate04EC5460" - }, - "Version": { - "Fn::GetAtt": [ - "LaunchTemplate04EC5460", - "LatestVersionNumber" - ] - } - }, - "RoleArn": { - "Fn::GetAtt": [ - "MyGameServerGroupServiceRoleD6701F0B", - "Arn" - ] - }, - "GameServerProtectionPolicy": "NO_PROTECTION", - "VpcSubnets": [ - { - "Ref": "VpcPublicSubnet1Subnet5C2D37C4" - }, - { - "Ref": "VpcPublicSubnet2Subnet691E08A3" - } - ] + "RoleArn": { + "Fn::GetAtt": [ + "MyGameServerGroupServiceRoleD6701F0B", + "Arn" + ] + }, + "BalancingStrategy": "ON_DEMAND_ONLY", + "GameServerProtectionPolicy": "FULL_PROTECTION", + "MaxSize": 10, + "MinSize": 1, + "VpcSubnets": [ + { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + }, + { + "Ref": "VpcPublicSubnet2Subnet691E08A3" } - } - }, - "Parameters": { - "BootstrapVersion": { - "Type": "AWS::SSM::Parameter::Value", - "Default": "/cdk-bootstrap/hnb659fds/version", - "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" - } - }, - "Rules": { - "CheckBootstrapVersion": { - "Assertions": [ - { - "Assert": { - "Fn::Not": [ + ] + } + } + }, + "Parameters": { + "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2" + }, + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], { - "Fn::Contains": [ - [ - "1", - "2", - "3", - "4", - "5" - ], - { - "Ref": "BootstrapVersion" - } - ] + "Ref": "BootstrapVersion" } ] - }, - "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." - } - ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." } - } - } \ No newline at end of file + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/manifest.json b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/manifest.json index c7d4fc3ddfa1d..97bde0478466e 100644 --- a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/manifest.json @@ -23,7 +23,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/1a74a356fdf93b28d3031ef4b2b5ee227f465b60ab8b0744e8e343a71014097b.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/0233f946355da9a29bd7caaf5049caf4cd4e71dfa10d084bd5ff56e547903847.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -183,6 +183,12 @@ "data": "LaunchTemplate04EC5460" } ], + "/aws-gamelift-game-server-group/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": [ + { + "type": "aws:cdk:logicalId", + "data": "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter" + } + ], "/aws-gamelift-game-server-group/MyGameServerGroup/ServiceRole/Resource": [ { "type": "aws:cdk:logicalId", diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/tree.json b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/tree.json index f6bf7a40ea0e6..486d29aa67194 100644 --- a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.js.snapshot/tree.json @@ -670,6 +670,9 @@ "aws:cdk:cloudformation:type": "AWS::EC2::LaunchTemplate", "aws:cdk:cloudformation:props": { "launchTemplateData": { + "imageId": { + "Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter" + }, "tagSpecifications": [ { "resourceType": "instance", @@ -715,6 +718,22 @@ "version": "0.0.0" } }, + "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": { + "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", + "path": "aws-gamelift-game-server-group/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118": { + "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", + "path": "aws-gamelift-game-server-group/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, "MyGameServerGroup": { "id": "MyGameServerGroup", "path": "aws-gamelift-game-server-group/MyGameServerGroup", @@ -803,7 +822,10 @@ "Arn" ] }, - "gameServerProtectionPolicy": "NO_PROTECTION", + "balancingStrategy": "ON_DEMAND_ONLY", + "gameServerProtectionPolicy": "FULL_PROTECTION", + "maxSize": 10, + "minSize": 1, "vpcSubnets": [ { "Ref": "VpcPublicSubnet1Subnet5C2D37C4" diff --git a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.ts b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.ts index 2dcc5077cf946..5a44e66394d92 100644 --- a/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.ts +++ b/packages/@aws-cdk/aws-gamelift/test/integ.game-server-group.ts @@ -3,6 +3,7 @@ import * as cdk from '@aws-cdk/core'; import { IntegTest } from '@aws-cdk/integ-tests'; import { Construct } from 'constructs'; import * as gamelift from '../lib'; +import { BalancingStrategy } from '../lib'; class TestStack extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { @@ -12,7 +13,9 @@ class TestStack extends cdk.Stack { const vpc = new ec2.Vpc(this, 'Vpc'); //Create default launch template - const launchTemplate = new ec2.LaunchTemplate(this, 'LaunchTemplate', {}); + const launchTemplate = new ec2.LaunchTemplate(this, 'LaunchTemplate', { + machineImage: ec2.MachineImage.latestAmazonLinux(), + }); new gamelift.GameServerGroup(this, 'MyGameServerGroup', { instanceDefinitions: [{ @@ -21,6 +24,10 @@ class TestStack extends cdk.Stack { { instanceType: ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE), }], + minSize: 1, + maxSize: 10, + protectGameServer: true, + balancingStrategy: BalancingStrategy.ON_DEMAND_ONLY, vpc: vpc, launchTemplate: launchTemplate, gameServerGroupName: 'test-gameservergroup-name', @@ -35,5 +42,4 @@ new IntegTest(app, 'GameServerGroup', { testCases: [stack], }); -app.synth(); - +app.synth(); \ No newline at end of file From 153c6dec49b35d012ba7fb99271a452dd63368fa Mon Sep 17 00:00:00 2001 From: Steve Houel Date: Tue, 8 Nov 2022 14:22:20 +0100 Subject: [PATCH 5/5] fix review comments: - remove addInstanceType function - remove not used tags property - add value check for minSize and maxSize --- .../aws-gamelift/lib/game-server-group.ts | 58 +++------------- .../test/game-server-group.test.ts | 69 +++---------------- 2 files changed, 22 insertions(+), 105 deletions(-) diff --git a/packages/@aws-cdk/aws-gamelift/lib/game-server-group.ts b/packages/@aws-cdk/aws-gamelift/lib/game-server-group.ts index 441149a8096c9..a212815c8c5b0 100644 --- a/packages/@aws-cdk/aws-gamelift/lib/game-server-group.ts +++ b/packages/@aws-cdk/aws-gamelift/lib/game-server-group.ts @@ -320,18 +320,6 @@ export interface GameServerGroupProps { * @default SPOT_PREFERRED */ readonly balancingStrategy?: BalancingStrategy; - - /** - * A list of labels to assign to the new game server group resource. - * Tags are developer-defined key-value pairs. - * Tagging AWS resources is useful for resource management, access management, and cost allocation. - * Once the resource is created, you can use `TagResource`, `UntagResource`, and `ListTagsForResource` to add, remove, and view tags, respectively. - * - * @see https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html - * - * @default {} - no tags - */ - readonly tags?: { [key: string]: string }; } /** @@ -429,11 +417,6 @@ export class GameServerGroup extends GameServerGroupBase { */ public readonly vpcSubnets?: ec2.SubnetSelection; - /** - * The set of Amazon EC2 instance types that GameLift FleetIQ can use when balancing and automatically scaling instances in the corresponding Auto Scaling group. - */ - private readonly instanceDefinitions: InstanceDefinition[] = []; - constructor(scope: Construct, id: string, props: GameServerGroupProps) { super(scope, id, { physicalName: props.gameServerGroupName, @@ -453,6 +436,14 @@ export class GameServerGroup extends GameServerGroupBase { this.vpcSubnets = props.vpcSubnets ?? { subnetType: ec2.SubnetType.PUBLIC }; const { subnetIds } = props.vpc.selectSubnets(this.vpcSubnets); + if (props.minSize && props.minSize < 0) { + throw new Error(`The minimum number of instances allowed in the Amazon EC2 Auto Scaling group cannot be lower than 0, given ${props.minSize}`); + } + + if (props.maxSize && props.maxSize < 1) { + throw new Error(`The maximum number of instances allowed in the Amazon EC2 Auto Scaling group cannot be lower than 1, given ${props.maxSize}`); + } + if (subnetIds.length > 20) { throw new Error(`No more than 20 subnets are allowed per game server group, given ${subnetIds.length}`); } @@ -461,7 +452,6 @@ export class GameServerGroup extends GameServerGroupBase { if (props.instanceDefinitions.length > 20) { throw new Error(`No more than 20 instance definitions are allowed per game server group, given ${props.instanceDefinitions.length}`); } - (props.instanceDefinitions || []).forEach(this.addInternalInstanceDefinition.bind(this)); this.role = props.role ?? new iam.Role(this, 'ServiceRole', { assumedBy: new iam.CompositePrincipal( @@ -479,7 +469,7 @@ export class GameServerGroup extends GameServerGroupBase { deleteOption: props.deleteOption, balancingStrategy: props.balancingStrategy, gameServerProtectionPolicy: props.protectGameServer ? 'FULL_PROTECTION' : 'NO_PROTECTION', - instanceDefinitions: cdk.Lazy.any({ produce: () => this.parseInstanceDefinitions() }), + instanceDefinitions: this.parseInstanceDefinitions(props), launchTemplate: this.parseLaunchTemplate(props), minSize: props.minSize, maxSize: props.maxSize, @@ -503,32 +493,6 @@ export class GameServerGroup extends GameServerGroupBase { } - /** - * Adds an instance definition that GameLift FleetIQ can use when balancing and automatically scaling instances in the corresponding Auto Scaling group - * - * @param instanceType An Amazon EC2 instance type designation. - * @param weight Instance weighting that indicates how much this instance type contributes to the total capacity of a game server group. - */ - public addInstanceDefinition(instanceType: ec2.InstanceType, weight?: number) { - this.addInternalInstanceDefinition({ - instanceType: instanceType, - weight: weight, - }); - } - - /** - * Adds an instance definition that GameLift FleetIQ can use when balancing and automatically scaling instances in the corresponding Auto Scaling group - * - * @param instanceDefinition The instance definition to add - */ - public addInternalInstanceDefinition(instanceDefinition: InstanceDefinition) { - if (this.instanceDefinitions.length == 20) { - throw new Error('No more than 20 instance definitions are allowed per game server group'); - } - - this.instanceDefinitions.push(instanceDefinition); - } - protected parseLaunchTemplate(props: GameServerGroupProps): CfnGameServerGroup.LaunchTemplateProperty { return { launchTemplateId: props.launchTemplate.launchTemplateId, @@ -550,8 +514,8 @@ export class GameServerGroup extends GameServerGroupBase { }; } - protected parseInstanceDefinitions(): CfnGameServerGroup.InstanceDefinitionProperty[] { - return this.instanceDefinitions.map(parseInstanceDefinition); + protected parseInstanceDefinitions(props: GameServerGroupProps): CfnGameServerGroup.InstanceDefinitionProperty[] { + return props.instanceDefinitions.map(parseInstanceDefinition); function parseInstanceDefinition(instanceDefinition: InstanceDefinition): CfnGameServerGroup.InstanceDefinitionProperty { return { diff --git a/packages/@aws-cdk/aws-gamelift/test/game-server-group.test.ts b/packages/@aws-cdk/aws-gamelift/test/game-server-group.test.ts index fa1fbe63e94b6..624bb3f7a350c 100644 --- a/packages/@aws-cdk/aws-gamelift/test/game-server-group.test.ts +++ b/packages/@aws-cdk/aws-gamelift/test/game-server-group.test.ts @@ -182,75 +182,28 @@ describe('gameservergroup', () => { })).toThrow(/No more than 20 instance definitions are allowed per game server group, given 21/); }); - test('with an incorrect instance definitions list', () => { - let incorrectInstanceDefinitions: gamelift.InstanceDefinition[] = []; - for (let i = 0; i < 20; i++) { - incorrectInstanceDefinitions.push({ + test('with incorrect minSize', () => { + expect(() => new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { + instanceDefinitions: [{ instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), - }); - } - const gameServerGroup = new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { - instanceDefinitions: incorrectInstanceDefinitions, + }], vpc: vpc, launchTemplate: launchTemplate, gameServerGroupName: 'test-name', - }); - expect(() => gameServerGroup.addInstanceDefinition(ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE))) - .toThrow(/No more than 20 instance definitions are allowed per game server group/); + minSize: -1, + })).toThrow(/The minimum number of instances allowed in the Amazon EC2 Auto Scaling group cannot be lower than 0, given -1/); }); - }); - describe('add instance definition', () => { - let stack: cdk.Stack; - let vpc: ec2.Vpc; - let launchTemplate: ec2.LaunchTemplate; - let gameServerGroup: gamelift.GameServerGroup; - - beforeEach(() => { - stack = new cdk.Stack(); - vpc = new ec2.Vpc(stack, 'vpc'); - launchTemplate = new ec2.LaunchTemplate(stack, 'LaunchTemplte', {}); - gameServerGroup = new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { + test('with incorrect maxSize', () => { + expect(() => new gamelift.GameServerGroup(stack, 'MyGameServerGroup', { instanceDefinitions: [{ instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE), }], vpc: vpc, launchTemplate: launchTemplate, - gameServerGroupName: 'test-gameservergroup-name', - }); - }); - - test('add new instance definition', () => { - // Add a new location - gameServerGroup.addInstanceDefinition(ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE)); - - Template.fromStack(stack).hasResource('AWS::GameLift::GameServerGroup', { - Properties: - { - InstanceDefinitions: [ - { InstanceType: 'c5.large' }, - { InstanceType: 'c4.large' }, - ], - }, - }); - }); - - test('add new instance definition with weight', () => { - // Add a new location - gameServerGroup.addInstanceDefinition(ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE), 10); - - Template.fromStack(stack).hasResource('AWS::GameLift::GameServerGroup', { - Properties: - { - InstanceDefinitions: [ - { InstanceType: 'c5.large' }, - { - InstanceType: 'c4.large', - WeightedCapacity: '10', - }, - ], - }, - }); + gameServerGroupName: 'test-name', + maxSize: -1, + })).toThrow(/The maximum number of instances allowed in the Amazon EC2 Auto Scaling group cannot be lower than 1, given -1/); }); });