Skip to content

Commit

Permalink
feat(aws-batch): support RuntimePlatform properties to ECS Fargate Co…
Browse files Browse the repository at this point in the history
…ntainer definition
  • Loading branch information
xazhao committed Jan 19, 2024
1 parent 2b59ed1 commit d871c9a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
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?.toString(),
operatingSystemFamily: this.fargateOperatingSystemFamily?.toString(),
},
};
};
}
Expand Down
24 changes: 24 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,30 @@ 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', {
RuntimePlatform: {
CpuArchitecture: ecs.CpuArchitecture.ARM64,
OperatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
},
});
});

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

0 comments on commit d871c9a

Please sign in to comment.