There wasn't a very good way to look it up, so I made it for the time being.
TD;DR
I did it using curl and python -c.
Supported versions are as follows
EC2: 1.21.0 or later version
Fargate: v1.3.0 or later version
Get $ {ECS_CONTAINER_METADATA_URI} / task
with curl, parse with python and get from TaskARN
#!/bin/bash
METADATA=$(curl ${ECS_CONTAINER_METADATA_URI}/task)
python3 -c "import json; meta=json.loads('$METADATA'); task_id=meta['TaskARN'].split('/')[-1]; print(task_id)" > ./task_id
TASK_ID=$(cat ./task_id)
Recommended Posts