Skip to content

Commit 5134552

Browse files
authored
Write Readme with examples
1 parent a462b48 commit 5134552

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,45 @@
11
# ecs_task_runner
22
Helper tools to run a task on AWS ECS and follow the logs
3+
4+
# Why?
5+
The use case why I created this script is that we want to run ECS tasks in Jenkins and directly see the output of the tasks that are being run. This is very cumbersome to achieve using the `aws cli`. Hence this library.
6+
7+
# Installation
8+
Until this package is distributed as pip package, you have to install it directly from this repository:
9+
10+
```
11+
pip install git+https://github.com/moee/ecs_task_runner@0.0.1
12+
```
13+
14+
# Usage
15+
## Example 1: Jenkins Integration
16+
17+
```sh
18+
#!/bin/sh
19+
pip install git+https://github.com/moee/ecs_task_runner@0.0.1
20+
21+
python << END
22+
import ecstaskrunner, sys, logging
23+
24+
logging.basicConfig()
25+
logging.getLogger('ecstaskrunner').setLevel(logging.INFO)
26+
27+
sys.exit(
28+
ecstaskrunner.run_task(
29+
cluster="YOUR-CLUSTER-NAME",
30+
taskDefinition='YOUR-TASK-DEFINITION',
31+
)
32+
)
33+
END
34+
```
35+
This runs the task named `YOUR-TASK-DEFINITION` on the cluster `YOUR-CLUSTER-NAME`, displays all the output (Note: this only works if the container definition uses the awslogs driver) and waits for the task to stop. Only if all containers have stopped and exited with `0` the job will be marked as success.
36+
37+
## Example 2: Get the log output of a task
38+
39+
```python
40+
import ecstaskrunner
41+
task = ecstaskrunner.task.Task(cluster='YOUR-CLUSTER-NAME', taskId='YOUR-TASK-ID')
42+
for container in task.containers:
43+
for line in task.containers[container].get_log_events():
44+
print "%s: %s" % (container, line)
45+
```

0 commit comments

Comments
 (0)