Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gamelift): support Build serverSdkVersion, updated OperatingSystem values #27857

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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