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

Is it possible to tag tasks? #249

Open
karanpratapsingh opened this issue Sep 23, 2021 · 3 comments
Open

Is it possible to tag tasks? #249

karanpratapsingh opened this issue Sep 23, 2021 · 3 comments

Comments

@karanpratapsingh
Copy link

Looking at the code, I see you use codedeploy.createDeployment function which doesn't doesn't allow for tagging task that'll be created like we can do with ecs.runTask...is there a possible approach?

@karanpratapsingh karanpratapsingh changed the title Is it possible to task tasks? Is it possible to tag tasks? Sep 23, 2021
@Lou1415926
Copy link
Contributor

Hello @karanpratapsingh ! Sorry for the late check-in 🙇🏼‍♀️ !

This action helps you update an existing ECS service with a task definition. As the starting and stopping of a task is controlled by the ECS service that it runs under, the action itself does not have the ability or permission to tag the tasks.

Here are a few suggestions that I have to achieve your goal:

Propagate Tags From Service Or Task Definition

If you specify PropagateTags at the time of your service creation, your tasks can be automatically tagged when it is spun up. This option is available in the AWS console experience, aws-cli, sdk, etc. However, it is only configurable at service creation time.

Tagging The Service

You can also just tag the service, and not the individual tasks. In order to reach the tasks spun up by that service, you can use the ListTasks API. You can tag the service through console, aws-cli, sdk, etc.

Tag Resources Manually

Finally, you can still opt to tag your individual tasks using the tag-resources API. Again, in aws-cli, from AWS console, whichever tools you like to use. This requires you to know the resource ARN, so it might be a bit of churn if you are looking to tag your tasks individually every time they are spun up :(

You can find more information about tagging ECS resources here as well.

Hope this helps!!

@karanpratapsingh
Copy link
Author

karanpratapsingh commented Oct 1, 2021

Thanks for the detailed answer @Lou1415926 , I ended up doing it with cli. Here's the script

#!/bin/bash

CLUSTER="$1"
SERVICE="$2"

PLATFORM_TAG="key=platform,value=Fargate"

# Tag new ECS tasks
for ARN in $(aws ecs list-tasks --cluster $CLUSTER --output text --query 'taskArns[*]' --service $SERVICE --no-cli-pager);
do
  echo "Tagging ARN: $ARN with $PLATFORM_TAG"
  aws ecs tag-resource --resource-arn $ARN --tags $PLATFORM_TAG --no-cli-pager;
done
usage: ./tag.sh staging-cluster svc-abc

@dgokcin
Copy link

dgokcin commented May 8, 2023

I see that this is an old issue but I would like to ask for your recommendation @Lou1415926 @karanpratapsingh

We have deployed our service with terraform and and the majority of our services were created without the ecs_service_tags. Than after a while we wanted to use those tags for some reporting purposes(cost dashboards) So after service creation we adderd the ecs_service_tags option is added to our terraform modules. We noticed that after a terraform apply, our resources were tagged properly but once a new docker imags is built in our CI and deployed using this action, the tags are gone.

We suspect that, because of the --query taskDefinition parameter in the action, although the output of the aws ecs describe-task-definition --region eu-west-1 --task-definition my-task-def-name --include TAGS > task_def command has tags, once the query option is added, the tags are not written to the task_def file and naturally, tags are gone in the next task definition.

Any idea what what approach should I do if I want the tags to persist and I do not want to avoid re-creating the services or using a script each time there is a deployment.

Thanks!

s3cube pushed a commit that referenced this issue Jul 16, 2024
Bumps [eslint](https://github.com/eslint/eslint) from 8.43.0 to 8.44.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](eslint/eslint@v8.43.0...v8.44.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@karanpratapsingh @dgokcin @Lou1415926 and others