Skip to content

Commit

Permalink
feat(gamelift): support Build serverSdkVersion, updated OperatingSyst…
Browse files Browse the repository at this point in the history
…em values (#27857)

Some adjustments to `Build` properties:
* Adds support for [`serverSdkVersion`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-gamelift-build.html#cfn-gamelift-build-serversdkversion) attribute
* Updates list of available [`operatingSystem`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-gamelift-build.html#cfn-gamelift-build-operatingsystem) and deprecates Windows Server 2012

Closes #27655.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
lpizzinidev authored and Mike Wrighton committed Nov 13, 2023
1 parent 60cfd4c commit e4c22a2
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-gamelift-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ new CfnOutput(this, 'BuildArn', { value: build.buildArn });
new CfnOutput(this, 'BuildId', { value: build.buildId });
```

To specify a server SDK version you used when integrating your game server build with Amazon GameLift use the `serverSdkVersion` parameter:

> See [Integrate games with custom game servers](https://docs.aws.amazon.com/gamelift/latest/developerguide/integration-custom-intro.html) for more details.
```ts
declare const bucket: s3.Bucket;
const build = new gamelift.Build(this, 'Build', {
content: gamelift.Content.fromBucket(bucket, "sample-asset-key"),
serverSdkVersion: '5.0.0',
});
```

#### Upload a realtime server Script

Your server script can include one or more files combined into a single .zip file for uploading. The .zip file must contain
Expand Down
48 changes: 47 additions & 1 deletion packages/@aws-cdk/aws-gamelift-alpha/lib/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,34 @@ export abstract class BuildBase extends cdk.Resource implements IBuild {
* The operating system that the game server binaries are built to run on.
*/
export enum OperatingSystem {
/**
* Amazon Linux operating system.
*/
AMAZON_LINUX = 'AMAZON_LINUX',

/**
* Amazon Linux 2 operating system.
*/
AMAZON_LINUX_2 = 'AMAZON_LINUX_2',
WINDOWS_2012 = 'WINDOWS_2012'

/**
* Amazon Linux 2023 operating system.
*/
AMAZON_LINUX_2023 = 'AMAZON_LINUX_2023',

/**
* Windows Server 2012 operating system.
*
* @deprecated If you have active fleets using the Windows Server 2012 operating system,
* you can continue to create new builds using this OS until October 10, 2023, when Microsoft ends its support.
* All others must use Windows Server 2016 when creating new Windows-based builds.
*/
WINDOWS_2012 = 'WINDOWS_2012',

/**
* Windows Server 2016 operating system.
*/
WINDOWS_2016 = 'WINDOWS_2016',
}

/**
Expand Down Expand Up @@ -137,6 +162,15 @@ export interface BuildProps {
* @default - a role will be created with default permissions.
*/
readonly role?: iam.IRole;

/**
* A server SDK version you used when integrating your game server build with Amazon GameLift.
*
* @see https://docs.aws.amazon.com/gamelift/latest/developerguide/integration-custom-intro.html
*
* @default - 4.0.2
*/
readonly serverSdkVersion?: string;
}

/**
Expand Down Expand Up @@ -247,6 +281,8 @@ export class Build extends BuildBase {
}
}

this.validateServerSdkVersion(props.serverSdkVersion);

this.role = props.role ?? new iam.Role(this, 'ServiceRole', {
assumedBy: new iam.ServicePrincipal('gamelift.amazonaws.com'),
});
Expand All @@ -263,6 +299,7 @@ export class Build extends BuildBase {
objectVersion: content.s3Location && content.s3Location.objectVersion,
roleArn: this.role.roleArn,
},
serverSdkVersion: props.serverSdkVersion,
});

resource.node.addDependency(this.role);
Expand All @@ -276,4 +313,13 @@ export class Build extends BuildBase {
});
}

private validateServerSdkVersion(serverSdkVersion?: string) {
if (serverSdkVersion === undefined || cdk.Token.isUnresolved(serverSdkVersion)) return;
if (!serverSdkVersion.match(/^\d+\.\d+\.\d+$/)) {
throw new Error(`serverSdkVersion must be in the 0.0.0 format, got \'${serverSdkVersion}\'.`);
}
if (serverSdkVersion.length > 128) {
throw new Error(`serverSdkVersion length must be smaller than or equal to 128, got ${serverSdkVersion.length}.`);
}
}
}
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-gamelift-alpha/test/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@ describe('build', () => {
buildName: buildName,
operatingSystem: gamelift.OperatingSystem.AMAZON_LINUX_2,
buildVersion: '1.0',
serverSdkVersion: '5.0.0',
});

Template.fromStack(stack).hasResourceProperties('AWS::GameLift::Build', {
Name: buildName,
OperatingSystem: gamelift.OperatingSystem.AMAZON_LINUX_2,
Version: '1.0',
ServerSdkVersion: '5.0.0',
});
});

Expand All @@ -183,6 +185,20 @@ describe('build', () => {
buildName: incorrectBuildName,
})).toThrow(/Build name can not be longer than 1024 characters but has 1025 characters./);
});

test('with an incorrect serverSdkVersion format', () => {
expect(() => new gamelift.Build(stack, 'BuildWithInvalidServerSdkVersion', {
content,
serverSdkVersion: 'invalid',
})).toThrow(/serverSdkVersion must be in the 0.0.0 format, got 'invalid'./);
});

test('with an incorrect serverSdkVersion length', () => {
expect(() => new gamelift.Build(stack, 'BuildWithInvalidServerSdkVersion', {
content,
serverSdkVersion: '1'.repeat(50) + '.' + '1'.repeat(50) + '.' + '1'.repeat(50),
})).toThrow(/serverSdkVersion length must be smaller than or equal to 128, got 152./);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
]
}
},
"Version": "1.0"
"Version": "1.0",
"ServerSdkVersion": "5.0.0"
},
"DependsOn": [
"BuildServiceRoleDefaultPolicyCB7101C6",
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-gamelift-alpha/test/integ.build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TestStack extends cdk.Stack {
content: gamelift.Content.fromAsset(path.join(__dirname, 'my-game-build')),
operatingSystem: gamelift.OperatingSystem.AMAZON_LINUX_2,
buildVersion: '1.0',
serverSdkVersion: '5.0.0',
});

new CfnOutput(this, 'BuildArn', { value: build.buildArn });
Expand Down

0 comments on commit e4c22a2

Please sign in to comment.