I have a pipeline setup to an ecs cluster in which I update the services' task definition and then launch a new deploy. E.g.:
# Update task definition
- aws ecs register-task-definition --cli-input-json file://aws/task-definition${TASK_SUFFIX}.json --region $AWS_DEFAULT_REGION
- TASK_REVISION=`aws ecs describe-task-definition --task-definition ${SERVICE_NAME}${TASK_SUFFIX} | egrep "revision" | tr "/" " " | awk '{print $2}' | sed 's/"$//'`
# Request service update:
- aws ecs update-service --service ${SERVICE_NAME} --cluster ${CLUSTER_NAME} --task-definition ${SERVICE_NAME}${TASK_SUFFIX}:${TASK_REVISION} --force-new-deployment
I have a scheduled task that uses the same task definition of a service, both using fargate. However, when I update my service's task definition, I have to manually update my scheduled task to the latest revision.
I would like to update my scheduled task's task definition to the latest revision whenever I update my service's task definition. Is it possible?
so for me this is working
aws events put-targets --cli-input-json file://.app_generic.json
app_generic.json
{
"Rule": "rule--app--generic",
"Targets": [
{
"Id": "app--generic",
"Arn": "arn:aws:ecs:us-east-1:xxxxxxx:cluster/my-cluster",
"RoleArn": "arn:aws:iam::xxxxxxx:role/ecsEventsRole",
"EcsParameters": {
"TaskDefinitionArn": "arn:aws:ecs:us-east-1:xxxxxxxx:task-definition/my-task-definitions",
"TaskCount": 1,
"LaunchType": "FARGATE",
"NetworkConfiguration": {
"awsvpcConfiguration": {
"Subnets": [
"subnet-xxxxx"
],
"SecurityGroups": [
"sg-xxxxxxx"
],
"AssignPublicIp": "ENABLED"
}
},
"PlatformVersion": "1.4.0"
}
}
]
}
Basically I have to re-put the rule, but by leaving out the revision number in TaskDefinitionArn, it's updated to the latest revision, while other container params (command, environment variables etc) persist. I suppose this is technically still 'manual', but the command can just be added after service update in CI/CD, bash script etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With