Skip to content

Commit f1bb801

Browse files
authored
feat(gamelift): support Build serverSdkVersion, updated OperatingSystem 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*
1 parent 5256de7 commit f1bb801

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

packages/@aws-cdk/aws-gamelift-alpha/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,18 @@ new CfnOutput(this, 'BuildArn', { value: build.buildArn });
187187
new CfnOutput(this, 'BuildId', { value: build.buildId });
188188
```
189189

190+
To specify a server SDK version you used when integrating your game server build with Amazon GameLift use the `serverSdkVersion` parameter:
191+
192+
> See [Integrate games with custom game servers](https://docs.aws.amazon.com/gamelift/latest/developerguide/integration-custom-intro.html) for more details.
193+
194+
```ts
195+
declare const bucket: s3.Bucket;
196+
const build = new gamelift.Build(this, 'Build', {
197+
content: gamelift.Content.fromBucket(bucket, "sample-asset-key"),
198+
serverSdkVersion: '5.0.0',
199+
});
200+
```
201+
190202
#### Upload a realtime server Script
191203

192204
Your server script can include one or more files combined into a single .zip file for uploading. The .zip file must contain

packages/@aws-cdk/aws-gamelift-alpha/lib/build.ts

+47-1
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,34 @@ export abstract class BuildBase extends cdk.Resource implements IBuild {
5252
* The operating system that the game server binaries are built to run on.
5353
*/
5454
export enum OperatingSystem {
55+
/**
56+
* Amazon Linux operating system.
57+
*/
5558
AMAZON_LINUX = 'AMAZON_LINUX',
59+
60+
/**
61+
* Amazon Linux 2 operating system.
62+
*/
5663
AMAZON_LINUX_2 = 'AMAZON_LINUX_2',
57-
WINDOWS_2012 = 'WINDOWS_2012'
64+
65+
/**
66+
* Amazon Linux 2023 operating system.
67+
*/
68+
AMAZON_LINUX_2023 = 'AMAZON_LINUX_2023',
69+
70+
/**
71+
* Windows Server 2012 operating system.
72+
*
73+
* @deprecated If you have active fleets using the Windows Server 2012 operating system,
74+
* you can continue to create new builds using this OS until October 10, 2023, when Microsoft ends its support.
75+
* All others must use Windows Server 2016 when creating new Windows-based builds.
76+
*/
77+
WINDOWS_2012 = 'WINDOWS_2012',
78+
79+
/**
80+
* Windows Server 2016 operating system.
81+
*/
82+
WINDOWS_2016 = 'WINDOWS_2016',
5883
}
5984

6085
/**
@@ -137,6 +162,15 @@ export interface BuildProps {
137162
* @default - a role will be created with default permissions.
138163
*/
139164
readonly role?: iam.IRole;
165+
166+
/**
167+
* A server SDK version you used when integrating your game server build with Amazon GameLift.
168+
*
169+
* @see https://docs.aws.amazon.com/gamelift/latest/developerguide/integration-custom-intro.html
170+
*
171+
* @default - 4.0.2
172+
*/
173+
readonly serverSdkVersion?: string;
140174
}
141175

142176
/**
@@ -247,6 +281,8 @@ export class Build extends BuildBase {
247281
}
248282
}
249283

284+
this.validateServerSdkVersion(props.serverSdkVersion);
285+
250286
this.role = props.role ?? new iam.Role(this, 'ServiceRole', {
251287
assumedBy: new iam.ServicePrincipal('gamelift.amazonaws.com'),
252288
});
@@ -263,6 +299,7 @@ export class Build extends BuildBase {
263299
objectVersion: content.s3Location && content.s3Location.objectVersion,
264300
roleArn: this.role.roleArn,
265301
},
302+
serverSdkVersion: props.serverSdkVersion,
266303
});
267304

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

316+
private validateServerSdkVersion(serverSdkVersion?: string) {
317+
if (serverSdkVersion === undefined || cdk.Token.isUnresolved(serverSdkVersion)) return;
318+
if (!serverSdkVersion.match(/^\d+\.\d+\.\d+$/)) {
319+
throw new Error(`serverSdkVersion must be in the 0.0.0 format, got \'${serverSdkVersion}\'.`);
320+
}
321+
if (serverSdkVersion.length > 128) {
322+
throw new Error(`serverSdkVersion length must be smaller than or equal to 128, got ${serverSdkVersion.length}.`);
323+
}
324+
}
279325
}

packages/@aws-cdk/aws-gamelift-alpha/test/build.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,14 @@ describe('build', () => {
163163
buildName: buildName,
164164
operatingSystem: gamelift.OperatingSystem.AMAZON_LINUX_2,
165165
buildVersion: '1.0',
166+
serverSdkVersion: '5.0.0',
166167
});
167168

168169
Template.fromStack(stack).hasResourceProperties('AWS::GameLift::Build', {
169170
Name: buildName,
170171
OperatingSystem: gamelift.OperatingSystem.AMAZON_LINUX_2,
171172
Version: '1.0',
173+
ServerSdkVersion: '5.0.0',
172174
});
173175
});
174176

@@ -183,6 +185,20 @@ describe('build', () => {
183185
buildName: incorrectBuildName,
184186
})).toThrow(/Build name can not be longer than 1024 characters but has 1025 characters./);
185187
});
188+
189+
test('with an incorrect serverSdkVersion format', () => {
190+
expect(() => new gamelift.Build(stack, 'BuildWithInvalidServerSdkVersion', {
191+
content,
192+
serverSdkVersion: 'invalid',
193+
})).toThrow(/serverSdkVersion must be in the 0.0.0 format, got 'invalid'./);
194+
});
195+
196+
test('with an incorrect serverSdkVersion length', () => {
197+
expect(() => new gamelift.Build(stack, 'BuildWithInvalidServerSdkVersion', {
198+
content,
199+
serverSdkVersion: '1'.repeat(50) + '.' + '1'.repeat(50) + '.' + '1'.repeat(50),
200+
})).toThrow(/serverSdkVersion length must be smaller than or equal to 128, got 152./);
201+
});
186202
});
187203
});
188204

packages/@aws-cdk/aws-gamelift-alpha/test/integ.build.js.snapshot/aws-gamelift-build.template.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
]
7373
}
7474
},
75-
"Version": "1.0"
75+
"Version": "1.0",
76+
"ServerSdkVersion": "5.0.0"
7677
},
7778
"DependsOn": [
7879
"BuildServiceRoleDefaultPolicyCB7101C6",

packages/@aws-cdk/aws-gamelift-alpha/test/integ.build.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class TestStack extends cdk.Stack {
1313
content: gamelift.Content.fromAsset(path.join(__dirname, 'my-game-build')),
1414
operatingSystem: gamelift.OperatingSystem.AMAZON_LINUX_2,
1515
buildVersion: '1.0',
16+
serverSdkVersion: '5.0.0',
1617
});
1718

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

0 commit comments

Comments
 (0)