> **Experimental**
>
> `@aws-cdk/aws-gamelift-alpha` is an [**experimental**](/stability) (alpha) package: its API may change in any release, without a major version bump.
# GameServerGroup

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.

Extends: Construct › Resource › GameServerGroupBase › GameServerGroup
Implements: IGameServerGroup, IResource, IGrantable, IEnvironmentAware, IConstruct, IDependable

- Stability: [Experimental](/cdk/api/stability.html)
- CloudFormation: [`AWS::GameLift::GameServerGroup`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-gamelift-gameservergroup.html)
- L1 type: [`CfnGameServerGroup`](/cdk/api/v2/docs/aws-cdk-lib.aws_gamelift.CfnGameServerGroup.html)
- Source: [`lib/game-server-group.ts`](https://github.com/aws/aws-cdk/blob/v2.276.0-alpha.0/packages/@aws-cdk/aws-gamelift-alpha/lib/game-server-group.ts#L356)

## 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 }
});
```

## Initializer

```ts
new GameServerGroup(scope: Construct, id: string, props: GameServerGroupProps)
```

## Construct Props

- `autoScalingPolicy`: [AutoScalingPolicy](/cdk/api/v2/docs/@aws-cdk_aws-gamelift-alpha.AutoScalingPolicy.html) — Configuration settings to define a scaling policy for the Auto Scaling group that is optimized for game hosting.

  **Default:** no autoscaling policy settled

  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.

- `balancingStrategy`: [BalancingStrategy](/cdk/api/v2/docs/@aws-cdk_aws-gamelift-alpha.BalancingStrategy.html) = SPOT_PREFERRED — Indicates how GameLift FleetIQ balances the use of Spot Instances and On-Demand Instances in the game server group.

- `deleteOption`: [DeleteOption](/cdk/api/v2/docs/@aws-cdk_aws-gamelift-alpha.DeleteOption.html) = SAFE_DELETE — The type of delete to perform.

  To delete a game server group, specify the DeleteOption

- `gameServerGroupName`: string (required) — A developer-defined identifier for the game server group.

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

- `instanceDefinitions`: [InstanceDefinition](/cdk/api/v2/docs/@aws-cdk_aws-gamelift-alpha.InstanceDefinition.html)[] (required) — The set of Amazon EC2 instance types that GameLift FleetIQ can use when balancing and automatically scaling instances in the corresponding Auto Scaling group.

- `launchTemplate`: [ILaunchTemplate](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ILaunchTemplate.html) (required) — 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.

- `maxSize`: number — 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.

- `minSize`: number — The minimum number of instances allowed in the Amazon EC2 Auto Scaling group.

  **Default:** the default is 0

  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.

- `protectGameServer`: boolean — 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

  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.

- `role`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — 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.

- `vpc`: [IVpc](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) (required) — 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.

- `vpcSubnets`: [SubnetSelection](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SubnetSelection.html) — Game server group subnet selection.

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

## Properties

- `autoScalingGroupArn`: string — The ARN of the generated AutoScaling group.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

  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.

- `gameServerGroupArn`: string — The ARN of the game server group.

- `gameServerGroupName`: string — The name of the game server group.

- `grantPrincipal`: [IPrincipal](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IPrincipal.html) — The principal this GameLift game server group is using.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `role`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM role that allows Amazon GameLift to access your Amazon EC2 Auto Scaling groups.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this resource is defined.

- `vpc`: [IVpc](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) — The VPC network to place the game server group in.

- `vpcSubnets`: [SubnetSelection](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SubnetSelection.html) — The game server group's subnets.

## Methods

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  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**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  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` (static) — Import an existing game server group from its attributes.

- `grant(grantee: IGrantable, ...actions: string[]): Grant` — [disable-awslint:no-grants].

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  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**

  - `x` — Any object.

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

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `metric(metricName: string, props?: MetricOptions): Metric` — Return the given named metric for this fleet.

- `toString(): string` — Returns a string representation of this construct.

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