Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create two CloudWatch Rules with the same target #3574

Closed
1 task done
0xdabbad00 opened this issue Aug 7, 2019 · 0 comments · Fixed by #3576
Closed
1 task done

Unable to create two CloudWatch Rules with the same target #3574

0xdabbad00 opened this issue Aug 7, 2019 · 0 comments · Fixed by #3576
Assignees
Labels
@aws-cdk/aws-events Related to CloudWatch Events needs-triage This issue or PR still needs to be triaged.

Comments

@0xdabbad00
Copy link

Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository's issues are intended for feature requests and bug reports.

  • I'm submitting a ...

    • 🪲 bug report
  • What is the current behavior?
    I create an ECS task, and then try to create two CloudWatch Event rules to start that task, one as a schedule and one as an event pattern. If I create either of these independently it works, but if I try to create both, it fails with:

./node_modules/@aws-cdk/core/lib/construct.ts:496
      throw new Error(`There is already a Construct with name '${childName}' in ${typeName}${name.length > 0 ? ' [' + name + ']' : ''}`);
            ^
Error: There is already a Construct with name 'PutTargets' in FargateTaskDefinition [taskDefinition]
    at ConstructNode.addChild (./node_modules/@aws-cdk/core/lib/construct.ts:496:13)
    at new ConstructNode (./node_modules/@aws-cdk/core/lib/construct.ts:143:18)
    at new Construct (./node_modules/@aws-cdk/core/lib/construct.ts:547:17)
    at new AwsCustomResource (./node_modules/@aws-cdk/custom-resources/lib/aws-custom-resource.ts:124:5)
    at EcsTask.bind (./node_modules/@aws-cdk/aws-events-targets/lib/ecs-task.ts:120:7)
    at Rule.addTarget (./node_modules/@aws-cdk/aws-events/lib/rule.ts:133:32)
    at new CloudmapperauditorStack (./lib/cloudmapperauditor-stack.js:121:10)
    at Object.<anonymous> (./bin/cloudmapperauditor.js:9:1)
    at Module._compile (internal/modules/cjs/loader.js:734:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)

An example code snippet is:

  var ecs_target = new targets.EcsTask({cluster: cluster, taskDefinition: taskDefinition});

    // Create rule to trigger this be run every 24 hours
    new events.Rule(this, "scheduled_run", {
      ruleName: "cloudmapper_scheduler",
      // Run at 2am EST (6am UTC) every night
      schedule: events.Schedule.expression("cron(0 6 * * ? *)"),
      description: "Starts the CloudMapper auditing task every night",
      targets: [ecs_target]
    });

    // Create rule to trigger this manually
    new events.Rule(this, "manual_run", {
      ruleName: "cloudmapper_manual_run",
      eventPattern: {source: ['cloudmapper']},
      description: "Allows CloudMapper auditing to be manually started",
      targets: [ecs_target]
    });

I don't know if this impacts resources other than ECS tasks. Commenting out the line for targets: [ecs_target] in either place allows this to run successfully, but the code above will fail with the error message above.

  • What is the expected behavior (or behavior of feature suggested)?
    I would like to be able to create two CloudWatch Rules, that each trigger the same target.

  • What is the motivation / use case for changing the behavior or adding this feature?
    I want to be able to run my ECS task on a schedule, but also be able to kick it off manually for testing or other needs.

  • Please tell us about your environment:

    • CDK CLI Version: 1.2.0
    • OS: OSX
    • Language: TypeScript
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)

@0xdabbad00 0xdabbad00 added the needs-triage This issue or PR still needs to be triaged. label Aug 7, 2019
jogold added a commit to jogold/aws-cdk that referenced this issue Aug 7, 2019
…iple rules

Also allow adding same scheduled fargate task multiple times to same rule.

Closes aws#3574
@eladb eladb added the @aws-cdk/aws-events Related to CloudWatch Events label Aug 13, 2019
@eladb eladb self-assigned this Aug 13, 2019
@eladb eladb added needs-triage This issue or PR still needs to be triaged. @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch @aws-cdk/aws-events Related to CloudWatch Events and removed needs-triage This issue or PR still needs to be triaged. @aws-cdk/aws-events Related to CloudWatch Events @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch labels Aug 13, 2019
@mergify mergify bot closed this as completed in #3576 Aug 19, 2019
mergify bot pushed a commit that referenced this issue Aug 19, 2019
…#3576)

* fix(events-targets): allow adding same scheduled fargate task to multiple rules

Also allow adding same scheduled fargate task multiple times to same rule.

Closes #3574

* create only one security group

* add tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-events Related to CloudWatch Events needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants