Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance run-task to allow streaming of logs from ecs task and waiting till completion #101

Closed
lokst opened this issue Apr 28, 2020 · 3 comments · Fixed by #167
Closed

Enhance run-task to allow streaming of logs from ecs task and waiting till completion #101

lokst opened this issue Apr 28, 2020 · 3 comments · Fixed by #167
Assignees
Labels
enhancement New feature or request

Comments

@lokst
Copy link
Contributor

lokst commented Apr 28, 2020

What would you like to be added

Add the ability to stream logs from an ecs task and wait till completion of the task being run by the orb.

Why is this needed

This is useful for long-running tasks like database migrator tasks.

Related references

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cmd-ecs-cli-logs.html

@lokst lokst added the enhancement New feature or request label Apr 28, 2020
@lokst lokst changed the title Stream logs from ecs task and wait till completion Enhance run-task to allow streaming of logs from ecs task and waiting till completion Apr 28, 2020
@gugu
Copy link

gugu commented May 9, 2020

Here is my piece of bash to wait till task completes and fail if container exit code is not 0:

set -euo pipefail
TASK_ARN=$(aws ecs list-tasks --family=authorizer-migration|jq '.taskArns[]' -r)
if [ -z "$TASK_ARN" ]; then
  echo "Task was not found"
  exit 1
fi
aws ecs wait tasks-stopped --tasks $TASK_ARN
aws ecs describe-tasks --tasks $TASK_ARN|jq -e '.tasks[0].containers[0].exitCode == 0'

Have no time for PR, hope someone can improve it to be usable

@jerryskye
Copy link

A slight variation of the above worked well for me as a replacement for the run-task step:

TASK_ARN="$(aws ecs run-task --cluster $ECS_CLUSTER_NAME --task-definition migrations-production --count 1 --launch-type EC2 | jq '.tasks[0].taskArn' -r)"
aws ecs wait tasks-stopped --cluster $ECS_CLUSTER_NAME --tasks $TASK_ARN
aws ecs describe-tasks --cluster $ECS_CLUSTER_NAME --tasks $TASK_ARN | jq -e '.tasks[0].containers[0].exitCode == 0'

Thanks @gugu 💚
I think streaming logs is only possible with the ecs-cli: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cmd-ecs-cli-logs.html

@brivu brivu self-assigned this Jan 10, 2022
@brivu
Copy link
Contributor

brivu commented Jun 9, 2022

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 output that contains the task-arn 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 else that's missing in this output that you need?

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

Best,
Brian

@brivu brivu linked a pull request Jun 9, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants