diff --git a/packages/@aws-cdk/aws-ecs-patterns/README.md b/packages/@aws-cdk/aws-ecs-patterns/README.md index 38915031f4346..8289145b4fb04 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/README.md +++ b/packages/@aws-cdk/aws-ecs-patterns/README.md @@ -305,6 +305,7 @@ const ecsScheduledTask = new ScheduledEc2Task(stack, 'ScheduledTask', { environment: { name: 'TRIGGER', value: 'CloudWatch Events' }, }, schedule: events.Schedule.expression('rate(1 minute)'), + enabled: true, ruleName: 'sample-scheduled-task-rule' }); ``` diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/base/scheduled-task-base.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/base/scheduled-task-base.ts index 38ac4e30a79af..7dc6492f42919 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/base/scheduled-task-base.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/base/scheduled-task-base.ts @@ -38,6 +38,13 @@ export interface ScheduledTaskBaseProps { */ readonly schedule: Schedule; + /** + * Indicates whether the rule is enabled. + * + * @default true + */ + readonly enabled?: boolean; + /** * A name for the rule. * @@ -148,6 +155,7 @@ export abstract class ScheduledTaskBase extends CoreConstruct { this.eventRule = new Rule(this, 'ScheduledEventRule', { schedule: props.schedule, ruleName: props.ruleName, + enabled: props.enabled, }); } diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.scheduled-ecs-task.ts b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.scheduled-ecs-task.ts index d96c8cd2edc7d..af262cd5de5ef 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.scheduled-ecs-task.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.scheduled-ecs-task.ts @@ -27,6 +27,7 @@ export = { // THEN expect(stack).to(haveResource('AWS::Events::Rule', { + State: 'ENABLED', Targets: [ { Arn: { 'Fn::GetAtt': ['EcsCluster97242B84', 'Arn'] }, @@ -78,6 +79,7 @@ export = { new ScheduledEc2Task(stack, 'ScheduledEc2Task', { cluster, + enabled: false, scheduledEc2TaskImageOptions: { image: ecs.ContainerImage.fromRegistry('henk'), memoryLimitMiB: 512, @@ -92,6 +94,7 @@ export = { // THEN expect(stack).to(haveResource('AWS::Events::Rule', { Name: 'sample-scheduled-task-rule', + State: 'DISABLED', Targets: [ { Arn: { 'Fn::GetAtt': ['EcsCluster97242B84', 'Arn'] }, diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/test.scheduled-fargate-task.ts b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/test.scheduled-fargate-task.ts index fa62f079862f1..9496288f3b235 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/test.scheduled-fargate-task.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/test.scheduled-fargate-task.ts @@ -24,6 +24,7 @@ export = { // THEN expect(stack).to(haveResource('AWS::Events::Rule', { + State: 'ENABLED', Targets: [ { Arn: { 'Fn::GetAtt': ['EcsCluster97242B84', 'Arn'] }, @@ -90,6 +91,7 @@ export = { new ScheduledFargateTask(stack, 'ScheduledFargateTask', { cluster, + enabled: false, scheduledFargateTaskImageOptions: { image: ecs.ContainerImage.fromRegistry('henk'), memoryLimitMiB: 512, @@ -104,6 +106,7 @@ export = { // THEN expect(stack).to(haveResource('AWS::Events::Rule', { Name: 'sample-scheduled-task-rule', + State: 'DISABLED', Targets: [ { Arn: { 'Fn::GetAtt': ['EcsCluster97242B84', 'Arn'] },