Skip to content

Commit ac8251f

Browse files
authored
feat(batch): add fargate Runtime Platform properties to ECS Fargate C… (#28841)
The property [RuntimePlatform](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-batch-jobdefinition-containerproperties.html#cfn-batch-jobdefinition-containerproperties-runtimeplatform) is not present in the AWS Batch ECS Fargate Job Definition. This PR adds flatten properties fargateCpuArchitecture and fargateOperatingSystemFamily to the ECS Fargate Job Definition in AWS Batch. Closes #26484. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 56794fc commit ac8251f

File tree

11 files changed

+105
-18
lines changed

11 files changed

+105
-18
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/BatchEcsJobDefinitionTestDefaultTestDeployAssertE5BAAC9B.assets.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/manifest.json

+8-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/stack.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/stack.template.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,11 @@
828828
"Type": "VCPU",
829829
"Value": "16"
830830
}
831-
]
831+
],
832+
"RuntimePlatform": {
833+
"CpuArchitecture": "ARM64",
834+
"OperatingSystemFamily": "LINUX"
835+
}
832836
},
833837
"JobDefinitionName": "foofoo",
834838
"Parameters": {

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/tree.json

+12-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.ts

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ new batch.EcsJobDefinition(stack, 'ECSFargateJobDefn', {
6060
memory: Size.mebibytes(32768),
6161
ephemeralStorageSize: Size.gibibytes(100),
6262
fargatePlatformVersion: FargatePlatformVersion.LATEST,
63+
fargateCpuArchitecture: ecs.CpuArchitecture.ARM64,
64+
fargateOperatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
6365
}),
6466
jobDefinitionName: 'foofoo',
6567
parameters: {

packages/aws-cdk-lib/aws-batch/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,21 @@ jobDefn.container.addVolume(batch.EcsVolume.efs({
479479
}));
480480
```
481481

482+
### Running an ECS workflow with Fargate container
483+
484+
```ts
485+
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
486+
container: new batch.EcsFargateContainerDefinition(this, 'myFargateContainer', {
487+
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
488+
memory: cdk.Size.mebibytes(2048),
489+
cpu: 256,
490+
ephemeralStorageSize: cdk.Size.gibibytes(100),
491+
fargateCpuArchitecture: ecs.CpuArchitecture.ARM64,
492+
fargateOperatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
493+
}),
494+
});
495+
```
496+
482497
### Secrets
483498

484499
You can expose SecretsManager Secret ARNs or SSM Parameters to your container as environment variables.

packages/aws-cdk-lib/aws-batch/lib/ecs-container-definition.ts

+36
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,20 @@ export interface IEcsFargateContainerDefinition extends IEcsContainerDefinition
979979
* @default - 20 GiB
980980
*/
981981
readonly ephemeralStorageSize?: Size;
982+
983+
/**
984+
* The vCPU architecture of Fargate Runtime.
985+
*
986+
* @default - X86_64
987+
*/
988+
readonly fargateCpuArchitecture?: ecs.CpuArchitecture;
989+
990+
/**
991+
* The operating system for the compute environment.
992+
*
993+
* @default - LINUX
994+
*/
995+
readonly fargateOperatingSystemFamily?: ecs.OperatingSystemFamily;
982996
}
983997

984998
/**
@@ -1009,6 +1023,20 @@ export interface EcsFargateContainerDefinitionProps extends EcsContainerDefiniti
10091023
* @default - 20 GiB
10101024
*/
10111025
readonly ephemeralStorageSize?: Size;
1026+
1027+
/**
1028+
* The vCPU architecture of Fargate Runtime.
1029+
*
1030+
* @default - X86_64
1031+
*/
1032+
readonly fargateCpuArchitecture?: ecs.CpuArchitecture;
1033+
1034+
/**
1035+
* The operating system for the compute environment.
1036+
*
1037+
* @default - LINUX
1038+
*/
1039+
readonly fargateOperatingSystemFamily?: ecs.OperatingSystemFamily;
10121040
}
10131041

10141042
/**
@@ -1018,12 +1046,16 @@ export class EcsFargateContainerDefinition extends EcsContainerDefinitionBase im
10181046
public readonly fargatePlatformVersion?: ecs.FargatePlatformVersion;
10191047
public readonly assignPublicIp?: boolean;
10201048
public readonly ephemeralStorageSize?: Size;
1049+
public readonly fargateCpuArchitecture?: ecs.CpuArchitecture;
1050+
public readonly fargateOperatingSystemFamily?: ecs.OperatingSystemFamily;
10211051

10221052
constructor(scope: Construct, id: string, props: EcsFargateContainerDefinitionProps) {
10231053
super(scope, id, props);
10241054
this.assignPublicIp = props.assignPublicIp;
10251055
this.fargatePlatformVersion = props.fargatePlatformVersion;
10261056
this.ephemeralStorageSize = props.ephemeralStorageSize;
1057+
this.fargateCpuArchitecture = props.fargateCpuArchitecture;
1058+
this.fargateOperatingSystemFamily = props.fargateOperatingSystemFamily;
10271059

10281060
// validates ephemeralStorageSize is within limits
10291061
if (props.ephemeralStorageSize) {
@@ -1050,6 +1082,10 @@ export class EcsFargateContainerDefinition extends EcsContainerDefinitionBase im
10501082
networkConfiguration: {
10511083
assignPublicIp: this.assignPublicIp ? 'ENABLED' : 'DISABLED',
10521084
},
1085+
runtimePlatform: {
1086+
cpuArchitecture: this.fargateCpuArchitecture?._cpuArchitecture,
1087+
operatingSystemFamily: this.fargateOperatingSystemFamily?._operatingSystemFamily,
1088+
},
10531089
};
10541090
};
10551091
}

packages/aws-cdk-lib/aws-batch/test/ecs-job-definition.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@ test('EcsJobDefinition uses Compatibility.FARGATE for Fargate containers', () =>
6363
});
6464
});
6565

66+
test('EcsJobDefinition uses runtimePlatform for Fargate containers', () => {
67+
// GIVEN
68+
const stack = new Stack();
69+
70+
// WHEN
71+
new EcsJobDefinition(stack, 'ECSJobDefn', {
72+
container: new EcsFargateContainerDefinition(stack, 'EcsContainer', {
73+
cpu: 256,
74+
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
75+
memory: Size.mebibytes(2048),
76+
fargateCpuArchitecture: ecs.CpuArchitecture.ARM64,
77+
fargateOperatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
78+
}),
79+
});
80+
81+
// THEN
82+
Template.fromStack(stack).hasResourceProperties('AWS::Batch::JobDefinition', {
83+
PlatformCapabilities: [Compatibility.FARGATE],
84+
});
85+
});
86+
6687
test('can be imported from ARN', () => {
6788
// GIVEN
6889
const stack = new Stack();

0 commit comments

Comments
 (0)