CircleCI-Public/aws-ecs-orb

Update run-task command to give access to the output from the aws cli

liron-quantum opened this issue · 2 comments

Describe Request:

The run-task command in that job is great for starting the job, but it doesn't save the output of the run-task command anywhere, which means that there's no easy way to check on the status of the task and wait for it to run before going onto the next build step.

If this functionality could be added to the orb, it would be fantastic.

Examples:

If the task IDs could be added into an environment variable, or if you could specify an output file that the orb command would pipe the output to.

For example, you could add:

run-output:
    description: |
          Specifies an output file on the local disk to save the output from the run-task CLI command.
    type: string

And then update the run_task script to be:

if [ -n "<<params.run-output>>" ]; then
  aws ecs run-task "$@" >> <<params.run-output>>
else
  aws ecs run-task "$@" 
fi
brivu commented

Hey @gugu,

I'm working on updating this orb at the moment and wanted to understand your request a little bit more. Right now, when running the run-task command, there's a json that's outputted like below:

    "tasks": [
        {
            "attachments": [],
            "attributes": [
                {
                    "name": "ecs.cpu-architecture",
                    "value": "x86_64"
                }
            ],
            "availabilityZone": "*********b",
            "clusterArn": "arn:aws:ecs:*********:************:cluster/*************-cluster",
            "containerInstanceArn": "arn:aws:ecs:*********:************:container-instance/*************-cluster/2c4f47871e1943479280dc1e8719eed0",
            "containers": [
                {
                    "containerArn": "arn:aws:ecs:*********:************:container/*************-cluster/164acb4a14b44e8084a6d18b851f4ff3/6dc7d919-0c9e-4a8b-9400-e442354f89eb",
                    "taskArn": "arn:aws:ecs:*********:************:task/*************-cluster/164acb4a14b44e8084a6d18b851f4ff3",
                    "name": "*****",
                    "image": "busybox",
                    "lastStatus": "PENDING",
                    "networkInterfaces": [],
                    "cpu": "0",
                    "memory": "256"
                }
            ],
            "cpu": "256",
            "createdAt": "2022-06-08T22:38:41.104000+00:00",
            "desiredStatus": "RUNNING",
            "enableExecuteCommand": false,
            "group": "family:*************-*****360",
            "lastStatus": "PENDING",
            "launchType": "EC2",
            "memory": "512",
            "overrides": {
                "containerOverrides": [
                    {
                        "name": "*****",
                        "memory": 512
                    }
                ],
                "inferenceAcceleratorOverrides": []
            },
            "tags": [],
            "taskArn": "arn:aws:ecs:*********:************:task/*************-cluster/164acb4a14b44e8084a6d18b851f4ff3",
            "taskDefinitionArn": "arn:aws:ecs:*********:************:task-definition/*************-*****360:116",
            "version": 1
        }
    ],
    "failures": []
}

Is there something in this output that you specifically need or is the goal just to check and see when this step is done so you can run the next one?

Please let me know and I'll see if we can add it for you.

Best,
Brian

I think this is what is of interest:

aws ecs wait tasks-stopped --cluster $CLUSTER --tasks $TASK_ID
ecs-cli logs --task-id=$TASK_ID --cluster $CLUSTER | awk NF
EXIT_CODE=$(aws ecs describe-tasks --cluster $CLUSTER --tasks $TASK_ID --query "tasks[0].containers[?name=='my-container'].exitCode" --output text)
[[ $EXIT_CODE -eq 0 ]]