简体   繁体   English

AWS ECS 任务定义更新

[英]AWS ECS Task definition update

I'm setting up new services in ECS and have updated my task definition many times.我正在 ECS 中设置新服务并多次更新我的任务定义。 When I do so, I need to edit the correspondent service and update the version to the latest.当我这样做时,我需要编辑相应的服务并将版本更新到最新。

Is there a way to automatically update an AWS service with the latest version of its correspondent task definition when it's updated?有没有办法在更新时使用其对应任务定义的最新版本自动更新 AWS 服务?

To force ECS service to re-evaluated the task definition and pull the new container image.强制 ECS 服务重新评估任务定义并拉取新的容器镜像。 use利用

aws ecs update-service --cluster cluster_name --service service_name --force-new-deployment aws ecs update-service --cluster cluster_name --service service_name --force-new-deployment

I think you have a couple of options here.我想你在这里有几个选择。 The first one is, depending on how you update the task def (manually? through a pipeline?) you could queue the force-new-deployment call for the service after the task update call.第一个是,根据您如何更新任务定义(手动?通过管道?),您可以在任务更新调用之后将服务的force-new-deployment调用排队。

If this is not possible (for reasons) and yet you need to automate this, you probably need to look at leveraging Event Bridge where you'd create a rule to intercept the update task definition api call you are making which would then invoke a Lambda that does the "force new deployment" on your behalf.如果这是不可能的(出于某种原因)并且您需要自动执行此操作,您可能需要查看利用 Event Bridge 来创建一个规则来拦截您正在进行的更新任务定义 api 调用,然后调用 Lambda代表您执行“强制新部署”。

The answer is yes, but it's a complicated process.答案是肯定的,但这是一个复杂的过程。 The best way I know is to use CodePipeline for your build automation, and have your build step produce a new taskdef.json and a new appspec.yml file as output artifacts.我知道的最好的方法是使用 CodePipeline 进行构建自动化,并让您的构建步骤生成一个新的taskdef.json和一个新的appspec.yml文件作为 output 工件。

These are then inputs to the deploy step.然后这些是部署步骤的输入。 Assuming you've set up a CodeDeploy Application, with a Deployment Group linked to a load balancer, you can then have CodeDeploy update your service to use the new task definition.假设您已经设置了 CodeDeploy 应用程序,并且部署组链接到负载均衡器,那么您可以让 CodeDeploy 更新您的服务以使用新的任务定义。

However, the key to making this work is to have the code that generates the new appspec.yml find the current revision number of the task definition and add 1 to it.然而,完成这项工作的关键是让生成新appspec.yml的代码找到任务定义的当前修订号并将其加 1。

Without incrementing the revision, it will just stay on the old version of the task def even though it will create the new revision.在不增加修订的情况下,即使它会创建新的修订,它也只会保留在任务 def 的旧版本上。

I've done this using the SDK, but I imagine you could do it with some cunning CLI scripts and jq .我已经使用 SDK 完成了此操作,但我想您可以使用一些巧妙的 CLI 脚本和jq来完成此操作。 For example, to find the latest version of the taskdef:例如,要查找最新版本的 taskdef:

aws ecs list-task-definitions --family-prefix <taskdef-family> --query 'taskDefinitionArns[-1]'

It's not too far from there to incrementing the revision number and building your new appspec.yml containing the 'next' revision of the taskdef.从那里增加修订号并构建包含 taskdef 的“下一个”修订的新appspec.yml并不远。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM