Home > Software engineering >  AWS Task Token with ECS
AWS Task Token with ECS

Time:06-19

I want to use the RunTask function from the ECS API with step functions to return a result from my ECS tasks.
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:

//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:

{  
   "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. Is there an API that I would pass this into to start the ECS task wioth the state - for example:

task = StartTask(THE ABOVE JSON)

And would this API allow me to get a response after it performs RunTask in the State:

MY_VALUE = task.task_token

CodePudding user response:

You don't call RunTask directly if you are using StepFunctions. StepFunctions would call ECS on your behalf.

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. As I stated in the answer to your previous question, RunTask never waits for the ECS task to complete. 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. 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.

  • Related