Get current instance features from within said instance

0

I've been working on some code that would benefit from some level of awareness about the platform on which its running. When it runs on bare metal, several options are available (lshw, hwloc and so on). In EC2 instances, this task is not so straight forward, as they run on virtualization (excluding bare metal instances, evidently). Running 'lshw' for instance, lists the hardware, that not necessarily corresponds with available resources. As an example, running lshw on a t2.micro instance, which has 1 default core available, gives the actual model of the CPU on which it is running, a Intel Xeon with 12 cores. I understand that I am able to fetch instance metadata, find which instance type the code is running on and use AWS CLI and/or EC2 API to get the description of the instance. The issue with that workaround is that it presupposes that the current instance has either the AWS CLI configured with proper credentials or that the user credentials are available as environment variables to the system, which may or may not be true. I've been looking for a more general solution, that could work, at least, on the most popular Linux distros, such as querying the system about actually available resources (cpus cores, threads, memory, cache and accelerators) but have so far failed to find a suitable solution. Is this possible? Or in this circumstances such query is not a possibility?

已提問 2 年前檢視次數 1243 次
1 個回答
1

I think your concern about credential availability is easily solved by assigning an Instance Profile (IAM Role) to the instance.

profile pictureAWS
專家
kentrad
已回答 2 年前
  • I see, but I believe that is not the optimal solution. Something that I failed to make clear on my original post is that the code on which I'm currently working on is intended to, eventually, become part of an open source project. This implies that third parties, unaware of the code inner workings, should be able to get it running out of the box with little to no setup required. I understand that are several ways to assure that credentials are available, but, I was hopping on finding a way to get such information, without relying on the user to correctly follow such instructions.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南