Skip to content

Commit

Permalink
feat(stepfunctions-tasks): add cpu and memory parameters to EcsRunTask
Browse files Browse the repository at this point in the history
  • Loading branch information
kackyt committed May 10, 2024
1 parent a1dcaa6 commit 6c74ef8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/ecs/run-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ export interface EcsRunTaskProps extends sfn.TaskStateBaseProps {
* @default false
*/
readonly enableExecuteCommand?: boolean;

/**
* Cpu setting override
*
* @default - No override
*/
readonly cpu?: string;

/**
* Memory setting override
*
* @default - No override
*/
readonly memoryMiB?: string;
}

/**
Expand Down Expand Up @@ -312,6 +326,8 @@ export class EcsRunTask extends sfn.TaskStateBase implements ec2.IConnectable {
NetworkConfiguration: this.networkConfiguration,
Overrides: renderOverrides(this.props.containerOverrides),
PropagateTags: this.props.propagatedTagSource,
Cpu: this.props.cpu,
Memory: this.props.memoryMiB,
...this.props.launchTarget.bind(this, { taskDefinition: this.props.taskDefinition, cluster: this.props.cluster }).parameters,
EnableExecuteCommand: this.props.enableExecuteCommand,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,60 @@ test('Running a task with NONE as propagated tag source', () => {
}).toStateJson())).toHaveProperty('Parameters.PropagateTags', 'NONE');
});

test('Running a task with cpu parameter', () => {
const taskDefinition = new ecs.TaskDefinition(stack, 'TD', {
memoryMiB: '1024',
cpu: '512',
compatibility: ecs.Compatibility.FARGATE,
});
const containerDefinition = taskDefinition.addContainer('TheContainer', {
containerName: 'ExplicitContainerName',
image: ecs.ContainerImage.fromRegistry('foo/bar'),
memoryLimitMiB: 256,
});

expect(stack.resolve(
new tasks.EcsRunTask(stack, 'task', {
cluster,
taskDefinition,
cpu: '1024',
containerOverrides: [
{
containerDefinition,
environment: [{ name: 'SOME_KEY', value: sfn.JsonPath.stringAt('$.SomeKey') }],
},
],
launchTarget: new tasks.EcsFargateLaunchTarget(),
}).toStateJson())).toHaveProperty('Parameters.Cpu', '1024');
});

test('Running a task with memory parameter', () => {
const taskDefinition = new ecs.TaskDefinition(stack, 'TD', {
memoryMiB: '1024',
cpu: '512',
compatibility: ecs.Compatibility.FARGATE,
});
const containerDefinition = taskDefinition.addContainer('TheContainer', {
containerName: 'ExplicitContainerName',
image: ecs.ContainerImage.fromRegistry('foo/bar'),
memoryLimitMiB: 256,
});

expect(stack.resolve(
new tasks.EcsRunTask(stack, 'task', {
cluster,
taskDefinition,
memoryMiB: '2048',
containerOverrides: [
{
containerDefinition,
environment: [{ name: 'SOME_KEY', value: sfn.JsonPath.stringAt('$.SomeKey') }],
},
],
launchTarget: new tasks.EcsFargateLaunchTarget(),
}).toStateJson())).toHaveProperty('Parameters.Memory', '2048');
});

test('Running a Fargate Task', () => {
const taskDefinition = new ecs.TaskDefinition(stack, 'TD', {
memoryMiB: '512',
Expand Down

0 comments on commit 6c74ef8

Please sign in to comment.