What should the functions do to obtain this information?
Call the DescribeInstances API operation and filter on the current instance ID. Examine the ElasticGpuAssociations property.
Evaluate the GPU AVAILABLE environment variable.
Call the DescribeElasticGpus API operation.
Retrieve the instance type from the instance metadata.
Explanations:
The DescribeInstances API operation provides details about instances but does not directly indicate if a GPU is available on the instance. ElasticGpuAssociations can give information about the attachment of Elastic GPUs, but it doesn’t confirm whether the instance itself is a GPU instance.
There is no standard GPU AVAILABLE environment variable in Amazon Linux instances. This option is not a valid method to determine if the instance is running on a GPU.
The DescribeElasticGpus API operation provides information about Elastic GPUs that are associated with instances, but it doesn’t directly indicate if an instance is a GPU instance by default. It would only show details for Elastic GPUs, not the instance itself.
The instance metadata endpoint provides the instance type and other attributes. By querying the instance metadata, the application can determine whether the instance type includes GPU resources (e.g.,p2,g4dn). This is the correct way to identify if the instance is a GPU instance.