Skip to content

Commit

Permalink
feat(batch): add fargate Runtime Platform properties to ECS Fargate C… (
Browse files Browse the repository at this point in the history
#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*
  • Loading branch information
xazhao authored and SankyRed committed Feb 8, 2024
1 parent d9401db commit c3f339d
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 18 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,11 @@
"Type": "VCPU",
"Value": "16"
}
]
],
"RuntimePlatform": {
"CpuArchitecture": "ARM64",
"OperatingSystemFamily": "LINUX"
}
},
"JobDefinitionName": "foofoo",
"Parameters": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ new batch.EcsJobDefinition(stack, 'ECSFargateJobDefn', {
memory: Size.mebibytes(32768),
ephemeralStorageSize: Size.gibibytes(100),
fargatePlatformVersion: FargatePlatformVersion.LATEST,
fargateCpuArchitecture: ecs.CpuArchitecture.ARM64,
fargateOperatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
}),
jobDefinitionName: 'foofoo',
parameters: {
Expand Down
15 changes: 15 additions & 0 deletions packages/aws-cdk-lib/aws-batch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,21 @@ jobDefn.container.addVolume(batch.EcsVolume.efs({
}));
```

### Running an ECS workflow with Fargate container

```ts
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
container: new batch.EcsFargateContainerDefinition(this, 'myFargateContainer', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
ephemeralStorageSize: cdk.Size.gibibytes(100),
fargateCpuArchitecture: ecs.CpuArchitecture.ARM64,
fargateOperatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
}),
});
```

### Secrets

You can expose SecretsManager Secret ARNs or SSM Parameters to your container as environment variables.
Expand Down
36 changes: 36 additions & 0 deletions packages/aws-cdk-lib/aws-batch/lib/ecs-container-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,20 @@ export interface IEcsFargateContainerDefinition extends IEcsContainerDefinition
* @default - 20 GiB
*/
readonly ephemeralStorageSize?: Size;

/**
* The vCPU architecture of Fargate Runtime.
*
* @default - X86_64
*/
readonly fargateCpuArchitecture?: ecs.CpuArchitecture;

/**
* The operating system for the compute environment.
*
* @default - LINUX
*/
readonly fargateOperatingSystemFamily?: ecs.OperatingSystemFamily;
}

/**
Expand Down Expand Up @@ -1009,6 +1023,20 @@ export interface EcsFargateContainerDefinitionProps extends EcsContainerDefiniti
* @default - 20 GiB
*/
readonly ephemeralStorageSize?: Size;

/**
* The vCPU architecture of Fargate Runtime.
*
* @default - X86_64
*/
readonly fargateCpuArchitecture?: ecs.CpuArchitecture;

/**
* The operating system for the compute environment.
*
* @default - LINUX
*/
readonly fargateOperatingSystemFamily?: ecs.OperatingSystemFamily;
}

/**
Expand All @@ -1018,12 +1046,16 @@ export class EcsFargateContainerDefinition extends EcsContainerDefinitionBase im
public readonly fargatePlatformVersion?: ecs.FargatePlatformVersion;
public readonly assignPublicIp?: boolean;
public readonly ephemeralStorageSize?: Size;
public readonly fargateCpuArchitecture?: ecs.CpuArchitecture;
public readonly fargateOperatingSystemFamily?: ecs.OperatingSystemFamily;

constructor(scope: Construct, id: string, props: EcsFargateContainerDefinitionProps) {
super(scope, id, props);
this.assignPublicIp = props.assignPublicIp;
this.fargatePlatformVersion = props.fargatePlatformVersion;
this.ephemeralStorageSize = props.ephemeralStorageSize;
this.fargateCpuArchitecture = props.fargateCpuArchitecture;
this.fargateOperatingSystemFamily = props.fargateOperatingSystemFamily;

// validates ephemeralStorageSize is within limits
if (props.ephemeralStorageSize) {
Expand All @@ -1050,6 +1082,10 @@ export class EcsFargateContainerDefinition extends EcsContainerDefinitionBase im
networkConfiguration: {
assignPublicIp: this.assignPublicIp ? 'ENABLED' : 'DISABLED',
},
runtimePlatform: {
cpuArchitecture: this.fargateCpuArchitecture?._cpuArchitecture,
operatingSystemFamily: this.fargateOperatingSystemFamily?._operatingSystemFamily,
},
};
};
}
Expand Down
21 changes: 21 additions & 0 deletions packages/aws-cdk-lib/aws-batch/test/ecs-job-definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ test('EcsJobDefinition uses Compatibility.FARGATE for Fargate containers', () =>
});
});

test('EcsJobDefinition uses runtimePlatform for Fargate containers', () => {
// GIVEN
const stack = new Stack();

// WHEN
new EcsJobDefinition(stack, 'ECSJobDefn', {
container: new EcsFargateContainerDefinition(stack, 'EcsContainer', {
cpu: 256,
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
memory: Size.mebibytes(2048),
fargateCpuArchitecture: ecs.CpuArchitecture.ARM64,
fargateOperatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
}),
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Batch::JobDefinition', {
PlatformCapabilities: [Compatibility.FARGATE],
});
});

test('can be imported from ARN', () => {
// GIVEN
const stack = new Stack();
Expand Down

0 comments on commit c3f339d

Please sign in to comment.