How to find the number of allocated vcpus inside a Fargate task?

0

We want to dynamically configure an application running on Fargate ECS to have one thread for each vcpu allocated to it.

The application parameter can be configured via an environment variable.

I'd like to fetch the number of vcpu's allocated from inside the task container and set the environment variable before starting the application.

Is there a way (e.g. a file under /sys, for instnace?) to fetch this when the task starts up?

Amos
질문됨 8달 전399회 조회
1개 답변
2
수락된 답변

Hi, if you simply want to get the number of threads in a task, you can run the following command.

root@ip-172-31-1-51:/usr/local/apache2# python3 -c 'import os; print(os.cpu_count())'
2

If you definitely want to get the number of vCPUs, you need to run aws ecs describe-task-definition command to fetch the vCPU info.

root@ip-172-31-1-51:/usr/local/apache2# PAGER=cat aws ecs describe-task-definition --task-definition MyTaskDefinition --query "taskDefinition.cpu" --output text
256
profile picture
HS
답변함 8달 전
profile picture
전문가
검토됨 19일 전
profile pictureAWS
전문가
검토됨 8달 전
  • Yes, section ContainerDefinitions provides what you are after: "containerDefinitions": [ { "environment": [], "name": "wordpress", "links": [ "mysql" ], "mountPoints": [], "image": "wordpress", "essential": true, "portMappings": [ { "containerPort": 80, "hostPort": 80 } ], "memory": 500, "cpu": 10, "volumesFrom": [] },

  • Thank you. It looks like the Python command you suggest would do the trick, assuming you mean that it can execute inside the container.

    The other answer will be trickier since I want to fetch this information from inside the container itself, without requiring direct AWS API access.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠