Skip to content

Commit

Permalink
chore(ecs-patterns): ScheduledFargateTaskProps is exposing unused pro…
Browse files Browse the repository at this point in the history
…ps from FargateServiceBaseProps (#26737)

`ScheduledFargateTaskProps` was extending the `FargateServiceBaseProps` interface.
The only property used from that interface is [`platformVersion`](https://github.com/aws/aws-cdk/blob/694b4067023d7422927dfde51cf9621395ca753b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/scheduled-fargate-task.ts#L97).

This change adds warning messages if the unused properties are specified:
- `taskDefinition`
- `cpu`
- `memoryLimitMiB`
- `runtimePlatform`

Closes #26702.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
lpizzinidev authored Aug 18, 2023
1 parent 58e87fb commit 52b43fc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Construct } from 'constructs';
import { FargateTaskDefinition } from '../../../aws-ecs';
import { EcsTask } from '../../../aws-events-targets';
import { Annotations } from '../../../core';
import { FargateServiceBaseProps } from '../base/fargate-service-base';
import { ScheduledTaskBase, ScheduledTaskBaseProps, ScheduledTaskImageProps } from '../base/scheduled-task-base';

Expand All @@ -23,7 +24,6 @@ export interface ScheduledFargateTaskProps extends ScheduledTaskBaseProps, Farga
* @default none
*/
readonly scheduledFargateTaskImageOptions?: ScheduledFargateTaskImageOptions;

}

/**
Expand Down Expand Up @@ -88,6 +88,19 @@ export class ScheduledFargateTask extends ScheduledTaskBase {
throw new Error('You must specify one of: taskDefinition or image');
}

if (props.taskDefinition) {
Annotations.of(this).addWarning('Property \'taskDefinition\' is ignored, use \'scheduledFargateTaskDefinitionOptions\' or \'scheduledFargateTaskImageOptions\' instead.');
}
if (props.cpu) {
Annotations.of(this).addWarning('Property \'cpu\' is ignored, use \'scheduledFargateTaskImageOptions.cpu\' instead.');
}
if (props.memoryLimitMiB) {
Annotations.of(this).addWarning('Property \'memoryLimitMiB\' is ignored, use \'scheduledFargateTaskImageOptions.memoryLimitMiB\' instead.');
}
if (props.runtimePlatform) {
Annotations.of(this).addWarning('Property \'runtimePlatform\' is ignored.');
}

// Use the EcsTask as the target of the EventRule
this.task = new EcsTask( {
cluster: this.cluster,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,35 @@ test('Scheduled Fargate Task - with list of tags', () => {
],
});
});

test('Scheduled Fargate Task - with unused properties', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 1 });
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });

new ScheduledFargateTask(stack, 'ScheduledFargateTask', {
cluster,
scheduledFargateTaskImageOptions: {
image: ecs.ContainerImage.fromRegistry('henk'),
memoryLimitMiB: 512,
},
schedule: events.Schedule.expression('rate(1 minute)'),
taskDefinition: new ecs.FargateTaskDefinition(stack, 'ScheduledFargateTaskDefinition'),
cpu: 256,
memoryLimitMiB: 512,
runtimePlatform: {
cpuArchitecture: ecs.CpuArchitecture.X86_64,
},
});

// THEN
Annotations.fromStack(stack).hasWarning(
'/Default/ScheduledFargateTask',
Match.stringLikeRegexp('Property \'taskDefinition\' is ignored, use \'scheduledFargateTaskDefinitionOptions\' or \'scheduledFargateTaskImageOptions\' instead.'),
);
Annotations.fromStack(stack).hasWarning('/Default/ScheduledFargateTask', Match.stringLikeRegexp('Property \'cpu\' is ignored, use \'scheduledFargateTaskImageOptions.cpu\' instead.'));
Annotations.fromStack(stack).hasWarning('/Default/ScheduledFargateTask', Match.stringLikeRegexp('Property \'memoryLimitMiB\' is ignored, use \'scheduledFargateTaskImageOptions.memoryLimitMiB\' instead.'));
Annotations.fromStack(stack).hasWarning('/Default/ScheduledFargateTask', Match.stringLikeRegexp('Property \'runtimePlatform\' is ignored.'));
});

0 comments on commit 52b43fc

Please sign in to comment.