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(batch): ephemeralStorage property on job definitions #25399

Merged
merged 31 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fe9d5ce
add ephemeralStorage property and unit test
sumupitchayan May 2, 2023
3854e10
add ephemeralStorage in README
sumupitchayan May 2, 2023
81efde2
add new prop to integ test
sumupitchayan May 2, 2023
0ec9174
Merge branch 'main' into sumughan/batch-add-ephemeralstorage-prop
sumupitchayan May 3, 2023
2af1f44
add new prop to IEcsContainerDefinition
sumupitchayan May 3, 2023
22e06ab
move ephemeral storage to Fargate class
sumupitchayan May 4, 2023
5d51fb2
add ephemeralStorage to CloudFormation and fix test format
sumupitchayan May 4, 2023
3d07bd1
update integ test snapshots
sumupitchayan May 4, 2023
1699e71
remove README typo
sumupitchayan May 4, 2023
c023e0e
remove test comments
sumupitchayan May 4, 2023
b71a742
Merge branch 'main' into sumughan/batch-add-ephemeralstorage-prop
sumupitchayan May 4, 2023
f95a4c8
Merge branch 'main' into sumughan/batch-add-ephemeralstorage-prop
sumupitchayan May 5, 2023
84c5040
Update packages/@aws-cdk/aws-batch-alpha/lib/ecs-container-definition.ts
sumupitchayan May 5, 2023
2719d0c
Update packages/@aws-cdk/aws-batch-alpha/lib/ecs-container-definition.ts
sumupitchayan May 5, 2023
cdc7006
Update packages/@aws-cdk/aws-batch-alpha/test/ecs-container-definitio…
sumupitchayan May 5, 2023
bdfb89a
rename to ephemeralStorageSize
sumupitchayan May 8, 2023
03b220c
finish renaming to ephemeralStorageSize
sumupitchayan May 8, 2023
8218d4c
add validation and unit test
sumupitchayan May 8, 2023
58b2ce5
make prop undefined by default
sumupitchayan May 8, 2023
c8023c3
refactor code for breaking change, moving executionRole property to E…
sumupitchayan May 9, 2023
c2e5e1d
Merge branch 'main' into sumughan/batch-add-ephemeralstorage-prop
sumupitchayan May 9, 2023
d341a1f
Kaizen suggestion - writing 20 GiB for default
sumupitchayan May 9, 2023
06e4dab
kaizen suggestion: simplify test case and use throw error('') instead…
sumupitchayan May 9, 2023
d36b2b3
add test adding ephemeralStorage as a Token
sumupitchayan May 9, 2023
06529b6
Merge branch 'main' into sumughan/batch-add-ephemeralstorage-prop
sumupitchayan May 9, 2023
72ace6e
fix calvin formatting suggestions
sumupitchayan Jun 8, 2023
62728cd
Update packages/@aws-cdk/aws-batch-alpha/lib/ecs-container-definition.ts
sumupitchayan Jun 8, 2023
b0c672b
Update packages/@aws-cdk/aws-batch-alpha/lib/ecs-container-definition.ts
sumupitchayan Jun 8, 2023
ef9727d
fix build failure by adding quotes within error expected error msg
sumupitchayan Jun 20, 2023
b025fbd
kaizen suggestion, remove creating new app in unit test
sumupitchayan Jun 20, 2023
97fded2
Merge branch 'main' into sumughan/batch-add-ephemeralstorage-prop
mergify[bot] Jun 20, 2023
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
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-batch-alpha/lib/ecs-container-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,13 @@ export interface IEcsFargateContainerDefinition extends IEcsContainerDefinition
* @default LATEST
*/
readonly fargatePlatformVersion?: ecs.FargatePlatformVersion;

/**
* The size for ephemeral storage.
*
* @default - no storage
sumupitchayan marked this conversation as resolved.
Show resolved Hide resolved
*/
readonly ephemeralStorage?: Size;
sumupitchayan marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -928,6 +935,13 @@ export interface EcsFargateContainerDefinitionProps extends EcsContainerDefiniti
* @default - a Role will be created
*/
readonly executionRole?: iam.IRole;

/**
* The size for ephemeral storage.
*
* @default - no storage
*/
readonly ephemeralStorage?: Size;
sumupitchayan marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -936,6 +950,7 @@ export interface EcsFargateContainerDefinitionProps extends EcsContainerDefiniti
export class EcsFargateContainerDefinition extends EcsContainerDefinitionBase implements IEcsFargateContainerDefinition {
public readonly fargatePlatformVersion?: ecs.FargatePlatformVersion;
public readonly assignPublicIp?: boolean;
public readonly ephemeralStorage?: Size;

/**
* The role used by Amazon ECS container and AWS Fargate agents to make AWS API calls on your behalf.
Expand All @@ -950,6 +965,7 @@ export class EcsFargateContainerDefinition extends EcsContainerDefinitionBase im
super(scope, id, props);
this.assignPublicIp = props.assignPublicIp;
this.fargatePlatformVersion = props.fargatePlatformVersion;
this.ephemeralStorage = props.ephemeralStorage;
this.executionRole = props.executionRole ?? createExecutionRole(this, 'ExecutionRole');
}

Expand All @@ -959,6 +975,9 @@ export class EcsFargateContainerDefinition extends EcsContainerDefinitionBase im
public _renderContainerDefinition(): CfnJobDefinition.ContainerPropertiesProperty {
return {
...super._renderContainerDefinition(),
ephemeralStorage: this.ephemeralStorage? {
sizeInGiB: this.ephemeralStorage?.toGibibytes(),
} : undefined,
fargatePlatformConfiguration: {
platformVersion: this.fargatePlatformVersion?.toString(),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,25 @@ describe('EC2 containers', () => {
},
});
});

// test('can add ephemeralStorage', () => {
// // WHEN
// new EcsJobDefinition(stack, 'ECSJobDefn', {
// container: new EcsFargateContainerDefinition(stack, 'EcsEc2Container', {
// ...defaultContainerProps,
// ephemeralStorage: Size.gibibytes(100),
// }),
// });

// // THEN
// Template.fromStack(stack).hasResourceProperties('AWS::Batch::JobDefinition', {
// ...pascalCaseExpectedProps,
// ContainerProperties: {
// ...pascalCaseExpectedProps.ContainerProperties,
// EphemeralStorage: Size.gibibytes(100),
// },
// });
// });
});

describe('Fargate containers', () => {
Expand Down Expand Up @@ -711,4 +730,29 @@ describe('Fargate containers', () => {
},
});
});
});

test('can set ephemeralStorage', () => {
// WHEN
new EcsJobDefinition(stack, 'ECSJobDefn', {
container: new EcsFargateContainerDefinition(stack, 'EcsFargateContainer', {
...defaultContainerProps,
fargatePlatformVersion: ecs.FargatePlatformVersion.LATEST,
ephemeralStorage: Size.gibibytes(100),
}),
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Batch::JobDefinition', {
...pascalCaseExpectedProps,
ContainerProperties: {
...pascalCaseExpectedProps.ContainerProperties,
ExecutionRoleArn: {
'Fn::GetAtt': ['EcsFargateContainerExecutionRole3286EAFE', 'Arn'],
},
EphemeralStorage: {
SizeInGiB: Size.gibibytes(100).toGibibytes(),
},
},
});
});
});
sumupitchayan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "30.1.0",
"version": "31.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"30.1.0"}
{"version":"31.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "30.1.0",
"version": "31.0.0",
"testCases": {
"BatchEcsJobDefinitionTest/DefaultTest": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "30.1.0",
"version": "31.0.0",
"artifacts": {
"stack.assets": {
"type": "cdk:asset-manifest",
Expand All @@ -17,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/c292a4e3a2a62cd3f3134971757eb866dc5224bc69f7109ec27d12ab882f2345.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/7eabaa659955f076359ed72f88d929cfe7651a904b6038ae0f3b3215ab36ac6c.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "30.1.0",
"version": "31.0.0",
"files": {
"c292a4e3a2a62cd3f3134971757eb866dc5224bc69f7109ec27d12ab882f2345": {
"7eabaa659955f076359ed72f88d929cfe7651a904b6038ae0f3b3215ab36ac6c": {
"source": {
"path": "stack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "c292a4e3a2a62cd3f3134971757eb866dc5224bc69f7109ec27d12ab882f2345.json",
"objectKey": "7eabaa659955f076359ed72f88d929cfe7651a904b6038ae0f3b3215ab36ac6c.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,9 @@
"Type": "container",
"ContainerProperties": {
"Environment": [],
"EphemeralStorage": {
"SizeInGiB": 100
},
"ExecutionRoleArn": {
"Fn::GetAtt": [
"myFargateContainerExecutionRoleB9EB79EA",
Expand Down
Loading