Skip to content

Commit

Permalink
feat(aws-ecs-patterns): allow ScheduledTaskBase be created in a DISAB…
Browse files Browse the repository at this point in the history
…LED state (#12837)

fixes #12836

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
ScottWalkerAU committed Feb 15, 2021
1 parent 4b0abbc commit c625699
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-ecs-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export = {

// THEN
expect(stack).to(haveResource('AWS::Events::Rule', {
State: 'ENABLED',
Targets: [
{
Arn: { 'Fn::GetAtt': ['EcsCluster97242B84', 'Arn'] },
Expand Down Expand Up @@ -78,6 +79,7 @@ export = {

new ScheduledEc2Task(stack, 'ScheduledEc2Task', {
cluster,
enabled: false,
scheduledEc2TaskImageOptions: {
image: ecs.ContainerImage.fromRegistry('henk'),
memoryLimitMiB: 512,
Expand All @@ -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'] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export = {

// THEN
expect(stack).to(haveResource('AWS::Events::Rule', {
State: 'ENABLED',
Targets: [
{
Arn: { 'Fn::GetAtt': ['EcsCluster97242B84', 'Arn'] },
Expand Down Expand Up @@ -90,6 +91,7 @@ export = {

new ScheduledFargateTask(stack, 'ScheduledFargateTask', {
cluster,
enabled: false,
scheduledFargateTaskImageOptions: {
image: ecs.ContainerImage.fromRegistry('henk'),
memoryLimitMiB: 512,
Expand All @@ -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'] },
Expand Down

0 comments on commit c625699

Please sign in to comment.