Skip to content

Commit 52b43fc

Browse files
authored
chore(ecs-patterns): ScheduledFargateTaskProps is exposing unused props 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*
1 parent 58e87fb commit 52b43fc

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/scheduled-fargate-task.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Construct } from 'constructs';
22
import { FargateTaskDefinition } from '../../../aws-ecs';
33
import { EcsTask } from '../../../aws-events-targets';
4+
import { Annotations } from '../../../core';
45
import { FargateServiceBaseProps } from '../base/fargate-service-base';
56
import { ScheduledTaskBase, ScheduledTaskBaseProps, ScheduledTaskImageProps } from '../base/scheduled-task-base';
67

@@ -23,7 +24,6 @@ export interface ScheduledFargateTaskProps extends ScheduledTaskBaseProps, Farga
2324
* @default none
2425
*/
2526
readonly scheduledFargateTaskImageOptions?: ScheduledFargateTaskImageOptions;
26-
2727
}
2828

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

91+
if (props.taskDefinition) {
92+
Annotations.of(this).addWarning('Property \'taskDefinition\' is ignored, use \'scheduledFargateTaskDefinitionOptions\' or \'scheduledFargateTaskImageOptions\' instead.');
93+
}
94+
if (props.cpu) {
95+
Annotations.of(this).addWarning('Property \'cpu\' is ignored, use \'scheduledFargateTaskImageOptions.cpu\' instead.');
96+
}
97+
if (props.memoryLimitMiB) {
98+
Annotations.of(this).addWarning('Property \'memoryLimitMiB\' is ignored, use \'scheduledFargateTaskImageOptions.memoryLimitMiB\' instead.');
99+
}
100+
if (props.runtimePlatform) {
101+
Annotations.of(this).addWarning('Property \'runtimePlatform\' is ignored.');
102+
}
103+
91104
// Use the EcsTask as the target of the EventRule
92105
this.task = new EcsTask( {
93106
cluster: this.cluster,

packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/scheduled-fargate-task.test.ts

+32
Original file line numberDiff line numberDiff line change
@@ -548,3 +548,35 @@ test('Scheduled Fargate Task - with list of tags', () => {
548548
],
549549
});
550550
});
551+
552+
test('Scheduled Fargate Task - with unused properties', () => {
553+
// GIVEN
554+
const stack = new cdk.Stack();
555+
const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 1 });
556+
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
557+
558+
new ScheduledFargateTask(stack, 'ScheduledFargateTask', {
559+
cluster,
560+
scheduledFargateTaskImageOptions: {
561+
image: ecs.ContainerImage.fromRegistry('henk'),
562+
memoryLimitMiB: 512,
563+
},
564+
schedule: events.Schedule.expression('rate(1 minute)'),
565+
taskDefinition: new ecs.FargateTaskDefinition(stack, 'ScheduledFargateTaskDefinition'),
566+
cpu: 256,
567+
memoryLimitMiB: 512,
568+
runtimePlatform: {
569+
cpuArchitecture: ecs.CpuArchitecture.X86_64,
570+
},
571+
});
572+
573+
// THEN
574+
Annotations.fromStack(stack).hasWarning(
575+
'/Default/ScheduledFargateTask',
576+
Match.stringLikeRegexp('Property \'taskDefinition\' is ignored, use \'scheduledFargateTaskDefinitionOptions\' or \'scheduledFargateTaskImageOptions\' instead.'),
577+
);
578+
Annotations.fromStack(stack).hasWarning('/Default/ScheduledFargateTask', Match.stringLikeRegexp('Property \'cpu\' is ignored, use \'scheduledFargateTaskImageOptions.cpu\' instead.'));
579+
Annotations.fromStack(stack).hasWarning('/Default/ScheduledFargateTask', Match.stringLikeRegexp('Property \'memoryLimitMiB\' is ignored, use \'scheduledFargateTaskImageOptions.memoryLimitMiB\' instead.'));
580+
Annotations.fromStack(stack).hasWarning('/Default/ScheduledFargateTask', Match.stringLikeRegexp('Property \'runtimePlatform\' is ignored.'));
581+
});
582+

0 commit comments

Comments
 (0)