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

[aws-events-targets] Support tagging when starting a Fargate task from CloudWatch Events #9823

Closed
2 tasks
zulhfreelancer opened this issue Aug 19, 2020 · 5 comments · Fixed by #23838
Closed
2 tasks
Labels
@aws-cdk/aws-events-targets effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1

Comments

@zulhfreelancer
Copy link

zulhfreelancer commented Aug 19, 2020

I saw this issue on aws/containers-roadmap and it's exactly the problem I'm facing now. I'm using EcsTask and EcsTaskProps to schedule Fargate tasks using CloudWatch Events rule. Since the scheduled task will run without ECS service, I can't use propagateTags or propagateTaskTagsFrom props.

Use Case

Mainly for billing. By having specific tags, I can use them in AWS Cost Explorer to see the cost breakdown for my scheduled tasks vs normal tasks (i.e. web containers).

Proposed Solution

Something like this would be great:

import events = require("@aws-cdk/aws-events");
import event_targets = require("@aws-cdk/aws-events-targets");

const rule = new events.Rule(this, "theRule", {
    enabled: true,
    // code omitted for brevity
});

rule.addTarget(
    new event_targets.EcsTask({
        // code omitted for brevity
        taskTags: [
            {
                key: "project",
                value: "my-cdk-project"
            },
            {
                key: "team",
                value: "team-a"
            }
        ]
    })
);

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@zulhfreelancer zulhfreelancer added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Aug 19, 2020
@SomayaB SomayaB assigned shivlaks and unassigned rix0rrr Aug 20, 2020
@shivlaks shivlaks added the p1 label Aug 31, 2020
@shivlaks shivlaks added effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Sep 15, 2020
@NGL321 NGL321 assigned rix0rrr and unassigned shivlaks Jan 25, 2021
@baxang
Copy link
Contributor

baxang commented Jun 24, 2021

Adding support for propagateTags would be great too! (As of now, CloudFormation doesn't seem to have this property)

Potentially related to aws-cloudformation/cloudformation-coverage-roadmap#394

@faabsen
Copy link

faabsen commented Nov 11, 2022

Any updates on this? Is there a known workaround to propagate the tags to an EcsRunTask started by a statemachine / event rule / schedule?

@fabiog27
Copy link

I'm also interested in updates to this issue. It seems from aws-cloudformation/cloudformation-coverage-roadmap#394 that it should be supported by CloudFormation now, but I can't see any options in cdk. I'm trying to add tags to a ScheduledFargateTask.

@faabsen
Copy link

faabsen commented Jan 2, 2023

I'm also interested in updates to this issue. It seems from aws-cloudformation/cloudformation-coverage-roadmap#394 that it should be supported by CloudFormation now, but I can't see any options in cdk. I'm trying to add tags to a ScheduledFargateTask.

I solved it via #14553 (comment), maybe this is an option for you too

@mergify mergify bot closed this as completed in #23838 Apr 18, 2023
mergify bot pushed a commit that referenced this issue Apr 18, 2023
…#23838)

This adds the ability to pass a tagList and the propagateTags flag to EC2 and Fargate ECS tasks triggered by an event. Users can leverage either or both of these attributes to apply tags an ECS task that's triggered through an Event. Both of these attributes are defined in the EcsParameters for a Rule https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-ecsparameters.html.

This closes #9823.

This is a non-breaking change. These new fields are added as optional with default values such that it won't impact existing stacks. Also note that these are two separate fields: a user can pass either or both but they're not dependent on each other since they have different uses. `propagateTags` will copy tags from the task definition, while `tagList` provides an explicit set of tags to be applied to the task but that are not on the task definition. In either case, these tags are separate from the tags on the EventBridge bus or Rule.

I did see that there was previously a PR opened for this in the past which was closed for staleness (#19583). There was a comment on there asking if this could be added to the existing tag system (#19583 (review)). I'm not sure if that would make sense in this case since the resource being created at deploy-time by CloudFormation isn't the resource being tagged. The event rule itself is instead being given the flag to pass along tags onto the Task that it's creating at some time in the future when the schedule triggers.I did see that there was previously a PR opened for this in the past which was closed for staleness (#19583). There was a comment on there asking if this could be added to the existing tag system (#19583 (review)). I'm not sure if that would make sense in this case since the resource being created at deploy-time by CloudFormation isn't the resource being tagged. The event rule itself is instead being given the flag to pass along tags onto the Task that it's creating at some time in the future when the schedule triggers.

----

### All Submissions:

* [x ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Construct Runtime Dependencies:

* [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies)

### New Features

* [x ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-events-targets effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1
Projects
None yet
6 participants