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

[ECS] [request]: Add ability to update task definition #2058

Open
tim-finnigan opened this issue Jun 29, 2023 · 3 comments
Open

[ECS] [request]: Add ability to update task definition #2058

tim-finnigan opened this issue Jun 29, 2023 · 3 comments
Labels
ECS Amazon Elastic Container Service Proposed Community submitted issue

Comments

@tim-finnigan
Copy link

tim-finnigan commented Jun 29, 2023

Please see aws/aws-sdk#406 for background and discussion.


Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Tell us about your request
What do you want us to build?

Which service(s) is this request for?
ECS [edited]

Tell us about the problem you're trying to solve. What are you trying to do, and why is it hard?
What outcome are you trying to achieve, ultimately, and why is it hard/impossible to do right now? What is the impact of not having this problem solved? The more details you can provide, the better we'll be able to understand and solve the problem.

Are you currently working around this issue?
How are you currently solving this problem?

Additional context
Anything else we should know?

Attachments
If you think you might have additional information that you'd like to include via an attachment, please do - we'll take a look. (Remember to remove any personally-identifiable information.)

@tim-finnigan tim-finnigan added the Proposed Community submitted issue label Jun 29, 2023
@jlbutler jlbutler added the ECS Amazon Elastic Container Service label Jul 11, 2023
@jlbutler
Copy link

I've tagged this ECS and edited the issue for service to improve tracking.

@ezhukov
Copy link

ezhukov commented Oct 24, 2023

Please prioritize this, because now I have to do the following in my CI yml just to update an image:

- >
  aws ecs describe-services
  --cluster $AWS_ECS_CLUSTER
  --services $AWS_ECS_SERVICE
  --query 'services[].taskDefinition[]'
  --output text |
  xargs aws ecs describe-task-definition --task-definition |
  jq --arg IMAGE $AWS_ECR/my-project:new-img-tag '.taskDefinition
  | .containerDefinitions[0].image = $IMAGE
  | del(.taskDefinitionArn)
  | del(.revision)
  | del(.status)
  | del(.requiresAttributes)
  | del(.compatibilities)
  | del(.registeredAt)
  | del(.registeredBy)' |
  xargs -0 aws ecs register-task-definition --cli-input-json |
  jq '.taskDefinition.taskDefinitionArn' |
  xargs aws ecs update-service
  --cluster $AWS_ECS_CLUSTER
  --service $AWS_ECS_SERVICE
  --task-definition

@ashikMostofaTonmoy
Copy link

ashikMostofaTonmoy commented May 7, 2024

I have slightly modified this that doesn't need 'jq' but can use custom tag

#!/bin/sh

# Define the full image name with tag
FULL_IMAGE="registry/project:mycustomtag"

# Retrieve details of the existing ECS task definition
TASK_DEFINITION=$(aws ecs describe-task-definition \
--task-definition "$TASK_DEFINATION_NAME" \
--region "$REGISTRY_REGION" \
--query '{  containerDefinitions: taskDefinition.containerDefinitions,
            family: taskDefinition.family,
            executionRoleArn: taskDefinition.executionRoleArn,
            volumes: taskDefinition.volumes,
            placementConstraints: taskDefinition.placementConstraints,
            cpu: taskDefinition.cpu,
            memory: taskDefinition.memory
            }')

# Modify the task definition to update the image name with the provided full image
NEW_TASK_DEFINITION=$(echo "$TASK_DEFINITION" | sed "s|\"image\": \".*\"|\"image\": \"$FULL_IMAGE\"|")
echo $NEW_TASK_DEFINITION

# Register the modified task definition
NEW_TASK_INFO=$(aws ecs register-task-definition \
      --region "$REGISTRY_REGION" \
      --cli-input-json "$NEW_TASK_DEFINITION")
echo $NEW_TASK_INFO

# Extract the revision number of the newly registered task definition
REVISION=$(echo "$NEW_TASK_INFO" | grep -o '"revision":[^,]*' | cut -d':' -f2)

# Remove leading and trailing whitespaces from the revision number
NEW_REVISION=$(echo $REVISION | tr -d ' ')
echo $NEW_REVISION

# Update ecs service
UPDATE_SERVICE=$(aws ecs update-service \
--region $REGISTRY_REGION \
--cluster ${CLUSTER_NAME} \
--service ${SERVICE_NAME} \
--task-definition ${TASK_DEFINATION_NAME}:${NEW_REVISION})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ECS Amazon Elastic Container Service Proposed Community submitted issue
Projects
None yet
Development

No branches or pull requests

4 participants