Skip to content
v2.276.0

Experimental

@aws-cdk/aws-gamelift-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

GameServerGroup L2 construct ​

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.

Example ​

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 }
});
python
# launch_template: ec2.ILaunchTemplate
# vpc: ec2.IVpc


gamelift.GameServerGroup(self, "GameServerGroup",
    game_server_group_name="sample-gameservergroup-name",
    instance_definitions=[gamelift.InstanceDefinition(
        instance_type=ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE)
    ), gamelift.InstanceDefinition(
        instance_type=ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE)
    )],
    launch_template=launch_template,
    vpc=vpc,
    vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PUBLIC)
)
java
ILaunchTemplate launchTemplate;
IVpc vpc;


GameServerGroup.Builder.create(this, "GameServerGroup")
        .gameServerGroupName("sample-gameservergroup-name")
        .instanceDefinitions(List.of(InstanceDefinition.builder()
                .instanceType(InstanceType.of(InstanceClass.C5, InstanceSize.LARGE))
                .build(), InstanceDefinition.builder()
                .instanceType(InstanceType.of(InstanceClass.C4, InstanceSize.LARGE))
                .build()))
        .launchTemplate(launchTemplate)
        .vpc(vpc)
        .vpcSubnets(SubnetSelection.builder().subnetType(SubnetType.PUBLIC).build())
        .build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.GameLift.Alpha
ILaunchTemplate launchTemplate;
IVpc vpc;


new GameServerGroup(this, "GameServerGroup", new GameServerGroupProps {
    GameServerGroupName = "sample-gameservergroup-name",
    InstanceDefinitions = new [] { new InstanceDefinition {
        InstanceType = InstanceType.Of(InstanceClass.C5, InstanceSize.LARGE)
    }, new InstanceDefinition {
        InstanceType = InstanceType.Of(InstanceClass.C4, InstanceSize.LARGE)
    } },
    LaunchTemplate = launchTemplate,
    Vpc = vpc,
    VpcSubnets = new SubnetSelection { SubnetType = SubnetType.PUBLIC }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdkgameliftalpha/v2
var launchTemplate ILaunchTemplate
var vpc IVpc


gamelift.NewGameServerGroup(this, jsii.String("GameServerGroup"), &GameServerGroupProps{
	GameServerGroupName: jsii.String("sample-gameservergroup-name"),
	InstanceDefinitions: []InstanceDefinition{
		&InstanceDefinition{
			InstanceType: ec2.InstanceType_Of(ec2.InstanceClass_C5, ec2.InstanceSize_LARGE),
		},
		&InstanceDefinition{
			InstanceType: ec2.InstanceType_*Of(ec2.InstanceClass_C4, ec2.InstanceSize_LARGE),
		},
	},
	LaunchTemplate: launchTemplate,
	Vpc: vpc,
	VpcSubnets: &SubnetSelection{
		SubnetType: ec2.SubnetType_PUBLIC,
	},
})

Initializer ​

ts
new GameServerGroup(scope: Construct, id: string, props: GameServerGroupProps)
python
GameServerGroup(scope: Construct, id: str, props: GameServerGroupProps)
java
new GameServerGroup(Construct scope, String id, GameServerGroupProps props)
csharp
new GameServerGroup(Construct scope, string id, GameServerGroupProps props)
go
NewGameServerGroup(Scope Construct, Id *string, Props GameServerGroupProps)

Construct Props ​

autoScalingPolicyoptionalAutoScalingPolicyauto_scaling_policyoptionalAutoScalingPolicyautoScalingPolicyoptionalAutoScalingPolicyAutoScalingPolicyoptionalAutoScalingPolicyAutoScalingPolicyoptionalAutoScalingPolicy#
Configuration settings to define a scaling policy for the Auto Scaling group that is optimized for game hosting.

Default: no autoscaling policy settled

notes

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.

balancingStrategyoptionalBalancingStrategybalancing_strategyoptionalBalancingStrategybalancingStrategyoptionalBalancingStrategyBalancingStrategyoptionalBalancingStrategyBalancingStrategyoptionalBalancingStrategy= SPOT_PREFERRED#
Indicates how GameLift FleetIQ balances the use of Spot Instances and On-Demand Instances in the game server group.
deleteOptionoptionalDeleteOptiondelete_optionoptionalDeleteOptiondeleteOptionoptionalDeleteOptionDeleteOptionoptionalDeleteOptionDeleteOptionoptionalDeleteOption= SAFE_DELETE#
The type of delete to perform.

To delete a game server group, specify the DeleteOption

gameServerGroupNamestringgame_server_group_namestrgameServerGroupNameStringGameServerGroupNamestringGameServerGroupName*stringrequired#
A developer-defined identifier for the game server group.

The name is unique for each Region in each AWS account.

instanceDefinitionsInstanceDefinition[]instance_definitionstyping.List[InstanceDefinition]instanceDefinitionsList<InstanceDefinition>InstanceDefinitionsInstanceDefinition[]InstanceDefinitions*[]InstanceDefinitionrequired#
The set of Amazon EC2 instance types that GameLift FleetIQ can use when balancing and automatically scaling instances in the corresponding Auto Scaling group.
launchTemplateILaunchTemplatelaunch_templateILaunchTemplatelaunchTemplateILaunchTemplateLaunchTemplateILaunchTemplateLaunchTemplateILaunchTemplaterequired#
The Amazon EC2 launch template that contains configuration settings and game server code to be deployed to all instances in the game server group.
notes

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.

maxSizeoptionalnumbermax_sizeoptionalint | floatmaxSizeoptionalNumberMaxSizeoptionaldoubleMaxSizeoptional*float64#
The maximum number of instances allowed in the Amazon EC2 Auto Scaling group.

Default: the default is 1

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.

minSizeoptionalnumbermin_sizeoptionalint | floatminSizeoptionalNumberMinSizeoptionaldoubleMinSizeoptional*float64#
The minimum number of instances allowed in the Amazon EC2 Auto Scaling group.

Default: the default is 0

notes

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.

protectGameServeroptionalbooleanprotect_game_serveroptionalboolprotectGameServeroptionalBooleanProtectGameServeroptionalboolProtectGameServeroptional*bool#
A flag that indicates whether instances in the game server group are protected from early termination.

Default: game servers running might be terminated during a scale-down event

notes

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.

roleoptionalIRoleroleoptionalIRoleroleoptionalIRoleRoleoptionalIRoleRoleoptionalIRole#
The IAM role that allows Amazon GameLift to access your Amazon EC2 Auto Scaling groups.

Default: a role will be created with default trust to Gamelift and Autoscaling service principal with a default policy GameLiftGameServerGroupPolicy attached.

vpcIVpcvpcIVpcvpcIVpcVpcIVpcVpcIVpcrequired#
The VPC network to place the game server group in.
notes

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.

vpcSubnetsoptionalSubnetSelectionvpc_subnetsoptionalSubnetSelectionvpcSubnetsoptionalSubnetSelectionVpcSubnetsoptionalSubnetSelectionVpcSubnetsoptionalSubnetSelection#
Game server group subnet selection.

Default: all GameLift FleetIQ-supported Availability Zones are used.

Properties ​

autoScalingGroupArnstringauto_scaling_group_arnstrautoScalingGroupArnStringAutoScalingGroupArnstringAutoScalingGroupArn*string#
The ARN of the generated AutoScaling group.
The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

gameServerGroupArnstringgame_server_group_arnstrgameServerGroupArnStringGameServerGroupArnstringGameServerGroupArn*string#
The ARN of the game server group.
gameServerGroupNamestringgame_server_group_namestrgameServerGroupNameStringGameServerGroupNamestringGameServerGroupName*string#
The name of the game server group.
grantPrincipalIPrincipalgrant_principalIPrincipalgrantPrincipalIPrincipalGrantPrincipalIPrincipalGrantPrincipalIPrincipal#
The principal this GameLift game server group is using.
nodeNodenodeNodenodeNodeNodeNodeNodeNode#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringstatic#
Uniquely identifies this class.
roleIRoleroleIRoleroleIRoleRoleIRoleRoleIRole#
The IAM role that allows Amazon GameLift to access your Amazon EC2 Auto Scaling groups.
stackStackstackStackstackStackStackStackStackStack#
The stack in which this resource is defined.
vpcIVpcvpcIVpcvpcIVpcVpcIVpcVpcIVpc#
The VPC network to place the game server group in.
vpcSubnetsmay be undefinedSubnetSelectionvpc_subnetsmay be undefinedSubnetSelectionvpcSubnetsmay be undefinedSubnetSelectionVpcSubnetsmay be undefinedSubnetSelectionVpcSubnetsmay be undefinedSubnetSelection#
The game server group's subnets.

Methods ​

applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

fromGameServerGroupAttributes(scope: Construct, id: string, attrs: GameServerGroupAttributes): IGameServerGroup@staticmethod def from_game_server_group_attributes(scope: Construct, id: str, attrs: GameServerGroupAttributes) -> IGameServerGrouppublic static IGameServerGroup fromGameServerGroupAttributes(Construct scope, String id, GameServerGroupAttributes attrs)public static IGameServerGroup FromGameServerGroupAttributes(Construct scope, string id, GameServerGroupAttributes attrs)func FromGameServerGroupAttributes(Scope Construct, Id *string, Attrs GameServerGroupAttributes) IGameServerGroupstatic#
Import an existing game server group from its attributes.
grant(grantee: IGrantable, ...actions: string[]): Grantdef grant(self, grantee: IGrantable, actions: str) -> Grantpublic Grant grant(IGrantable grantee, String actions)public Grant Grant(IGrantable grantee, string actions)func Grant(Grantee IGrantable, Actions *string) Grant#
[disable-awslint:no-grants].
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
metric(metricName: string, props?: MetricOptions): Metricdef metric(self, metric_name: str, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metric(String metricName, MetricOptions props)public Metric Metric(string metricName, MetricOptions? props = null)func Metric(MetricName *string, Props MetricOptions) Metric#
Return the given named metric for this fleet.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.