-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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): add Build L2 constructs for GameLift #22313
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ca35900
feat(gamelift): Adding Build L2 construct
stevehouel b9fc99d
Adding missing file ignored by gitignore
stevehouel 65f63c4
Merge branch 'main' into houes/rfc-436
stevehouel 4198d32
Merge branch 'main' into houes/rfc-436
mergify[bot] e2cb700
Improve code documentation for Build and Content ressource
stevehouel a782433
Merge branch 'main' into houes/rfc-436
stevehouel efd89d0
Upgrading integ tests to fit refactoring
stevehouel 39699ac
Fixing rosetta issues
stevehouel c630331
Merge branch 'main' into houes/rfc-436
stevehouel fd85aa8
Merge branch 'main' into houes/rfc-436
stevehouel 53d4263
Update build.ts
otaviomacedo fe4be27
Update README.md
otaviomacedo 6f24103
Merge branch 'main' into houes/rfc-436
stevehouel 23c3f3e
Merge branch 'main' into houes/rfc-436
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
import * as iam from '@aws-cdk/aws-iam'; | ||
import * as s3 from '@aws-cdk/aws-s3'; | ||
import * as s3_assets from '@aws-cdk/aws-s3-assets'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import { Construct } from 'constructs'; | ||
import { Content } from './content'; | ||
import { CfnBuild } from './gamelift.generated'; | ||
|
||
/** | ||
* Represents a GameLift server build. | ||
*/ | ||
export interface IBuild extends cdk.IResource, iam.IGrantable { | ||
|
||
/** | ||
* The Identifier of the build. | ||
* | ||
* @attribute | ||
*/ | ||
readonly buildId: string; | ||
} | ||
|
||
/** | ||
* Base class for new and imported GameLift server build. | ||
*/ | ||
export abstract class BuildBase extends cdk.Resource implements IBuild { | ||
/** | ||
* The Identifier of the build. | ||
*/ | ||
public abstract readonly buildId: string; | ||
|
||
public abstract readonly grantPrincipal: iam.IPrincipal; | ||
} | ||
|
||
/** | ||
* The operating system that the game server binaries are built to run on. | ||
*/ | ||
export enum OperatingSystem { | ||
AMAZON_LINUX = 'AMAZON_LINUX', | ||
AMAZON_LINUX_2 = 'AMAZON_LINUX_2', | ||
WINDOWS_2012 = 'WINDOWS_2012' | ||
} | ||
|
||
|
||
/** | ||
* Represents a Build content defined outside of this stack. | ||
*/ | ||
export interface BuildAttributes { | ||
/** | ||
* The identifier of the build | ||
*/ | ||
readonly buildId: string; | ||
/** | ||
* The IAM role assumed by GameLift to access server build in S3. | ||
* @default - undefined | ||
*/ | ||
readonly role?: iam.IRole; | ||
} | ||
|
||
/** | ||
* Properties for a new build | ||
*/ | ||
export interface BuildProps { | ||
/** | ||
* Name of this build | ||
* | ||
* @default No name | ||
*/ | ||
readonly buildName?: string; | ||
|
||
/** | ||
* Version of this build | ||
* | ||
* @default No version | ||
*/ | ||
readonly buildVersion?: string; | ||
|
||
/** | ||
* The operating system that the game server binaries are built to run on. | ||
* | ||
* @default No version | ||
*/ | ||
readonly operatingSystem?: OperatingSystem; | ||
|
||
/** | ||
* The game build file storage | ||
*/ | ||
readonly content: Content; | ||
|
||
/** | ||
* The IAM role assumed by GameLift to access server build in S3. | ||
* If providing a custom role, it needs to trust the GameLift service principal (gamelift.amazonaws.com) and be granted sufficient permissions | ||
* to have Read access to a specific key content into a specific S3 bucket. | ||
* Below an example of required permission: | ||
* { | ||
* "Version": "2012-10-17", | ||
* "Statement": [{ | ||
* "Effect": "Allow", | ||
* "Action": [ | ||
* "s3:GetObject", | ||
* "s3:GetObjectVersion" | ||
* ], | ||
* "Resource": "arn:aws:s3:::bucket-name/object-name" | ||
* }] | ||
*} | ||
* | ||
* @see https://docs.aws.amazon.com/gamelift/latest/developerguide/security_iam_id-based-policy-examples.html#security_iam_id-based-policy-examples-access-storage-loc | ||
* | ||
* @default - a role will be created with default permissions. | ||
*/ | ||
readonly role?: iam.IRole; | ||
} | ||
|
||
/** | ||
* A GameLift build, that is installed and runs on instances in an Amazon GameLift fleet. It consists of | ||
* a zip file with all of the components of the game server build. | ||
* | ||
* @see https://docs.aws.amazon.com/gamelift/latest/developerguide/gamelift-build-cli-uploading.html | ||
* | ||
* @resource AWS::GameLift::Build | ||
*/ | ||
export class Build extends BuildBase { | ||
|
||
/** | ||
* Create a new Build from s3 content | ||
*/ | ||
static fromBucket(scope: Construct, id: string, bucket: s3.IBucket, key: string, objectVersion?: string) { | ||
return new Build(scope, id, { | ||
content: Content.fromBucket(bucket, key, objectVersion), | ||
}); | ||
} | ||
|
||
/** | ||
* Create a new Build from asset content | ||
*/ | ||
static fromAsset(scope: Construct, id: string, path: string, options?: s3_assets.AssetOptions) { | ||
return new Build(scope, id, { | ||
content: Content.fromAsset(path, options), | ||
}); | ||
} | ||
|
||
/** | ||
* Import a build into CDK using its identifier | ||
*/ | ||
static fromBuildId(scope: Construct, id: string, buildId: string): IBuild { | ||
return this.fromBuildAttributes(scope, id, { buildId }); | ||
} | ||
|
||
/** | ||
* Import an existing build from its attributes. | ||
*/ | ||
static fromBuildAttributes(scope: Construct, id: string, attrs: BuildAttributes): IBuild { | ||
class Import extends BuildBase { | ||
public readonly buildId = attrs.buildId; | ||
public readonly grantPrincipal = attrs.role ?? new iam.UnknownPrincipal({ resource: this }); | ||
} | ||
|
||
return new Import(scope, id); | ||
} | ||
|
||
/** | ||
* The Identifier of the build. | ||
*/ | ||
public readonly buildId: string; | ||
|
||
/** | ||
* The IAM role GameLift assumes to acccess server build content. | ||
*/ | ||
public readonly role: iam.IRole; | ||
|
||
/** | ||
* The principal this GameLift Build is using. | ||
*/ | ||
public readonly grantPrincipal: iam.IPrincipal; | ||
|
||
constructor(scope: Construct, id: string, props: BuildProps) { | ||
super(scope, id, { | ||
physicalName: props.buildName, | ||
}); | ||
|
||
if (props.buildName && !cdk.Token.isUnresolved(props.buildName)) { | ||
if (props.buildName.length > 1024) { | ||
throw new Error(`Build name can not be longer than 1024 characters but has ${props.buildName.length} characters.`); | ||
} | ||
} | ||
this.role = props.role ?? new iam.Role(this, 'ServiceRole', { | ||
assumedBy: new iam.ServicePrincipal('gamelift.amazonaws.com'), | ||
}); | ||
this.grantPrincipal = this.role; | ||
const content = props.content.bind(this, this.role); | ||
|
||
const resource = new CfnBuild(this, 'Resource', { | ||
name: props.buildName, | ||
version: props.buildVersion, | ||
operatingSystem: props.operatingSystem, | ||
storageLocation: { | ||
bucket: content.s3Location && content.s3Location.bucketName, | ||
key: content.s3Location && content.s3Location.objectKey, | ||
objectVersion: content.s3Location && content.s3Location.objectVersion, | ||
roleArn: this.role.roleArn, | ||
}, | ||
}); | ||
|
||
this.buildId = resource.ref; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm: you don't need to pass any policies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am granting read access to for an S3 bucket + dedicated content key on binding phase for a content (see content.ts on bind methods) but otherwise no specific needs here or any specific policy