5

I want to make sure that the task is running the latest image.

Within the container, I can get the docker image ID (such as 183f9552f0a5) by calling http://169.254.170.2/v2/metadata, however I am looking for a way to get it on my laptop.

Is this possible with AWS CLI or SDK?

aosho235
  • 123
  • 1
  • 2
  • 15

1 Answers1

0

You first need to get the Task Definition ARN for the Task using describe_tasks. You can skip this step if you already know the ARN.

aws ecs describe-tasks --tasks TASK_ARN

Then you can use describe_task_definition to get the image name.

aws ecs describe-task-definition --task-definition TASKDEF_ARN
dmulter
  • 2,608
  • 3
  • 15
  • 24
  • 2
    `aws ecs describe-task-definition --task-definition TASKDEF_ARN | jq .taskDefinition.containerDefinitions[].image` showed the image URL like `XXXXXXXXXXXXXX.dkr.ecr.ap-northeast-1.amazonaws.com/sinatra2:latest`, but what I'm looking for is the docker image ID like `183f9552f0a5`. Is it possible to obtain it? – aosho235 Feb 15 '19 at 01:05
  • Yes, I see now that was what you asked for. If the images are in ECR, you could use [`describe-images`](https://docs.aws.amazon.com/cli/latest/reference/ecr/describe-images.html) to retrieve the image ID given the repository name and tag. Other repos could offer similar APIs to retrieve the image ID as I believe it is simply a SHA digest of the image itself. – dmulter Feb 15 '19 at 06:20
  • 4
    I'm using ECR, but consider this scenario: 1. push image as `latest` 2. deploy the image in ECS 3. rebuild image and push again as `latest` 4. get the image URL and SHA digest from ECS/ECR In this case, the CLI would report the new digest. I need the exact digest of the image that ECS is running. – aosho235 Feb 15 '19 at 07:24
  • 1
    I think you are out of luck. I would open a feature request with AWS. – dmulter Feb 15 '19 at 14:26
  • 1
    I'm trying to figure out the same thing. – stuff22 Feb 27 '19 at 23:31