-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(events-targets): Add tagging for ECS tasks triggered by an event #23838
Conversation
…ed event Add the ability to set tags for ECS tasks triggered by a scheduled event
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
I'll get a README update added here, it looks like that got lost in the shuffle as this was cut over from #23666 |
Fixed a few minor issues on existing README entries that Rosetta threw errors on
✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.
logEvent: targets.LogGroupTargetInput({ | ||
timestamp: events.EventField.from('$.time'), | ||
message: events.EventField.from('$.detail-type'), | ||
logEvent: targets.LogGroupTargetInput.fromObject({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heads up to reviewers: these updates that aren't specifically related to ECS were required because they would not compile when running Rosetta.
…ed in a separate chore PR later
Pulling in this convo from the last PR to continue. Firstly, thank you for splitting this up! I appreciate the extra effort so we can provide better feedback! Can you help me understand why |
@Mergifyio update |
✅ Branch has been successfully updated |
@@ -118,12 +148,17 @@ export class EcsTask implements events.IRuleTarget { | |||
this.taskDefinition = props.taskDefinition; | |||
this.taskCount = props.taskCount ?? 1; | |||
this.platformVersion = props.platformVersion; | |||
this.propagateTags = props.propagateTags === true ? ecs.PropagatedTagSource.TASK_DEFINITION : undefined ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is giving me pause. If CloudFormation expects something other than a true or false here, I think we're potentially setting ourselves up for breaking changes if they ever add more allowed values here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see how this could become problematic even though this is the only allowed value today. I can update this so it takes a value of type ecs.PropagatedTagSource
and then validates that you passed the correct value with some helpful messaging. That way if a new source is ever added, the validation can be removed or modified accordingly and existing code won't break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
This comment also gives me some pause simply because I'm not sure of the answer here. Asking for some additional feedback from the team. |
Yep, so when an ECS Task is triggered by an event, A use case example: I might want to tag all of my tasks with my team's cost allocation tags, so I'll apply those to the task definition and set them to propagate when triggered by an event using Ultimately this rolls into the discussion of why I don't think this makes sense to roll up into the CDK tagging model as well. The code that was modified here creates an Event Rule. But what's being tagged isn't that Rule, it's the ECS Task that's created at some point in the future whenever the Rule fires. |
…olean to avoid breaking changes should the allowed values change in the future
Pull request has been modified.
@TheRealAmazonKendra Have you had a chance to talk with the team and take another look at this PR? |
Hey, sorry for the delay on this! One more question about the potential interdependency between the two props. Would you have a tagsList even when you aren't using |
@Mergifyio update |
❌ Base branch update has failedrefusing to allow a GitHub App to create or update workflow |
Yep, you could pass either parameter separately or both together. So for example you might pass a For this example I'd set it up something like: rule.addTarget(
new targets.EcsTask( {
cluster: cluster,
taskDefinition: taskDefinition,
tagList: [
{
key: 'triggeredBy',
value: 'schedule',
},
],
})
); Now even if my task definition has say 25 other tags on it, the only tag that gets applied to the running task that was triggered by this event rule will be |
Hey @TheRealAmazonKendra, have you had a chance to take another look at this and my response above? |
Apologies for the delay. I was unexpectedly out of the office for a few weeks. I will re-review this in the next day or two. |
This PR has been in the MERGE CONFLICTS state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week. |
This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple more comments and then I think we are good!
@@ -7,6 +7,20 @@ import { Construct } from 'constructs'; | |||
import { ContainerOverride } from './ecs-task-properties'; | |||
import { addToDeadLetterQueueResourcePolicy, bindBaseTargetConfig, singletonEventRole, TargetBaseProps } from './util'; | |||
|
|||
/** | |||
* Tag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update this description to give details on what this is? Also the
docstring for key
and value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the docstrings here
* | ||
* @default - No tags are applied to the task | ||
*/ | ||
readonly tagList?: Tag[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about just tags
? I don't think we need to say List
since the type tells
you it is a list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that tags
is probably better here. I chose tagList
initially to match the CloudFormation parameter name https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-ecsparameters.html#cfn-events-rule-ecsparameters-taglist. Since this is a level 2 construct though I suppose there's no need to faithfully match that naming and will get that update applied.
@@ -337,3 +337,33 @@ rule.addTarget(new targets.EventBus( | |||
), | |||
)); | |||
``` | |||
|
|||
## Run an ECS Task |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a little section here about tags? Based on the conversation so far
on this PR I think it would help users to understand the different types of tags
and how they are used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that sounds good, I'm not sure why GitHub isn't showing this diff as outdated now but I've gone ahead and added some clarifying notes about tagging here.
This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state. |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
This was enabled by PR #23838 which adds support for the `propagateTags` and `tags` attributes to the ecs-patterns module. With the changes in this PR, tags can now be applied to tasks that are launched as scheduled tasks with the proper tags passed through to the event target. This PR contributes to (but does not completely close) #25106 . ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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, whiletagList
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:
Adding new Construct Runtime Dependencies:
New Features
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