简体   繁体   English

带有 ECS 的 AWS 任务令牌

[英]AWS Task Token with ECS

I want to use the RunTask function from the ECS API with step functions to return a result from my ECS tasks.我想使用 ECS API 中的 RunTask 函数和 step 函数来返回我的 ECS 任务的结果。
In the code that calls RunTask will the code pause and wait until StepFunction gets a success or failure status and would I be able to read the response after the API RunTask call:在调用 RunTask 的代码中,代码将暂停并等待 StepFunction 获得成功或失败状态,并且我能否在 API RunTask 调用后读取响应:

//code...
var = RunTask(with Task Token...)
//will the program pause until the Task Token gets a response? and

//would I be able to add code here to read the value from the TaskToken?
String = var.TaskToken

//code...

Edit: On AWS webpage( https://docs.aws.amazon.com/step-functions/latest/dg/connect-ecs.html ) step function integration with ECS RunTask is shown as this:编辑:在 AWS 网页上 ( https://docs.aws.amazon.com/step-functions/latest/dg/connect-ecs.html ) 与 ECS RunTask 的步骤函数集成如下所示:

{  
   "StartAt":"Manage ECS task",
   "States":{  
      "Manage ECS task":{  
         "Type":"Task",
         "Resource":"arn:aws:states:::ecs:runTask.waitForTaskToken",
         "Parameters":{  
            "LaunchType":"FARGATE",
            "Cluster":"cluster-arn",
            "TaskDefinition":"job-id",
            "Overrides":{  
               "ContainerOverrides":[  
                  {  
                     "Name":"container-name",
                     "Environment":[  
                        {  
                           "Name":"TASK_TOKEN_ENV_VARIABLE",
                           "Value.$":"$$.Task.Token"
                        }
                     ]
                  }
               ]
            }
         },
         "End":true
      }
   }
}

I am slightly confused as how I would use this in my golang code.我对如何在我的 golang 代码中使用它感到有些困惑。 Is there an API that I would pass this into to start the ECS task wioth the state - for example:是否有一个 API 可以传递给我以启动 ECS 任务与状态 - 例如:

task = StartTask(THE ABOVE JSON)

And would this API allow me to get a response after it performs RunTask in the State:这个 API 是否允许我在状态中执行 RunTask 后得到响应:

MY_VALUE = task.task_token

You don't call RunTask directly if you are using StepFunctions.如果您使用 StepFunctions,则不要直接调用 RunTask。 StepFunctions would call ECS on your behalf . StepFunctions 将代表您调用 ECS

However, if you are getting a task token from StepFunctions through some other means, and then calling RunTask in your own code, then the answer is no.但是,如果您通过其他方式从 StepFunctions 获取任务令牌,然后在您自己的代码中调用 RunTask,那么答案是否定的。 As I stated in the answer to your previous question, RunTask never waits for the ECS task to complete.正如我在上一个问题的答案中所说,RunTask永远不会等待 ECS 任务完成。 It doesn't even wait for it to start.它甚至不等它开始。

So no, whatever code you are writing, wherever it is running, will not wait for an ECS task to complete and return a response after calling RunTask.所以不,无论您正在编写什么代码,无论它在哪里运行,都不会等待 ECS 任务完成并在调用 RunTask 后返回响应。 That's why you want StepFunctions to manage the ECS task for you, because StepFunctions will pause the state machine (if you have it configured to run the task in waitForTaskToken mode) and wait for your ECS task to issue a callback to StepFunctions with the task token once it is done .这就是您希望 StepFunctions 为您管理 ECS 任务的原因,因为 StepFunctions 将暂停状态机(如果您已将其配置为在waitForTaskToken模式下运行任务)并等待您的 ECS 任务使用任务令牌向 StepFunctions 发出回调一旦完成

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

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