Search code examples
amazon-web-servicesaws-step-functions

Setting Resource Arn from Output of step of AWS Step Function


I have a step function where I want to start by getting the resourceArn for an ECS Cluster and then invoke tasks on that cluster.

However, I'm having difficulty dynamically passing the arn from step to step.

{
 "StartAt": "GetArnLambda",
 "States": {
   "GetArnLambda": {
     "Type": "Task",
     "Resource": "arn:aws:lambda:us-east-1:AWS_ACCOUNT_ID:function:FUNCTION_NAME",
     "Next": "ecs_task"
   },
   "ecs_task": {
     "Type": "Task",
     "Resource": "arn:aws:states:::ecs:runTask.sync",
     "Parameters": {
                "Cluster": "$.arn",
                "TaskDefinition": "ecs_task_def"
            },
     "End": true
    } 
}

And I get as output from GetArnLambda

{
  "name": "GetArnLambda",
  "output": {
    "arn": "arn:aws:ecs:us-east-1:AWS_ACCOUNT_ID:cluster/CLUSTER_NAME"
  }
}

But this interprets the Cluster arn as "$.arn". How can I reference the arn I just received from the first task?


Solution

  • From the documentation:

    Use "Parameters" field to create a collection of key-value pairs that are passed as input. The values of each can either be static values that you include in your state machine definition, or selected from either the input or the context object with a path. For key-value pairs where the value is selected using a path, the key name must end in .$.

    So I think you need:

     "Parameters": {
                "Cluster.$": "$.arn",
                "TaskDefinition": "ecs_task_def"
            },