code: def get_image_id(
      ec2_client: botocore.client.BaseClient, cuda: bool
  ) -> str:
      image_name = (
          f"dstack-{version.base_image}"
          if not cuda
          else f"dstack-cuda-{version.base_image}"
      )
  
      response = ec2_client.describe_images(
          Filters=[{"Name": "name", "Values": [image_name]}]
      )
      images = sorted(
          (i for i in response["Images"] if i["State"] == "available"),
          key=lambda i: i["CreationDate"],
          reverse=True,
      )
      if not images:
          raise ResourceNotFoundError()
      return images[0]["ImageId"]
  
file_path: dstack/src/dstack/_internal/core/backends/aws/resources.py
imports: import json
  from typing import Any, Dict, List, Optional
  import botocore.client
  import botocore.exceptions
  import dstack.version
  from dstack._internal.core.errors import ResourceNotFoundError
label_desc: Use image node_id 1 for calling a global function with example usage: get_image_id(ec2_client, cuda) and returns: images