code: def deploy_aws(command: str, args: argparse.Namespace) -> None:
      if args.profile:
          boto3_session = boto3.Session(
              profile_name=args.profile, region_name=args.region
          )
      else:
          boto3_session = boto3.Session(region_name=args.region)
  
      if (
          boto3_session.region_name
          not in constants.misc.SUPPORTED_REGIONS
      ):
          print(
              f"`det deploy` is only supported in {constants.misc.SUPPORTED_REGIONS} - "
              f"tried to deploy to {boto3_session.region_name}"
          )
          raise CliError(
              "use the --region argument to deploy to a supported region"
          )
  
      if command == "list":
          try:
              output = aws.list_stacks(boto3_session)
          except NoCredentialsError:
              error_no_credentials()
          except Exception:
              raise CliError(
                  "Listing stacks failed. Check the AWS CloudFormation Console for details.",
              )
          for item in output:
              print(item["StackName"])
          return
  
      # TODO(DET-4258) Uncomment this when we fully support all P3 regions.
      # if boto3_session.region_name == "eu-west-2" and args.agent_instance_type is None:
      #     print(
      #         "the default agent instance type for `det deploy` (p2.8xlarge) is not available in "
      #         "eu-west-2 (London).  Please specify an --agent-instance-type argument."
      #     )
      #     sys.exit(1)
  
      if not re.match(
          constants.misc.CLOUDFORMATION_REGEX, args.cluster_id
      ):
          raise CliError(
              "Deployment Failed - cluster-id much match ^[a-zA-Z][-a-zA-Z0-9]*$"
          )
  
      if command == "down":
          if not args.yes:
              val = input(
                  "Deleting an AWS stack will lose all your data, including the created network "
                  "file system. Please back up the file system before deleting it. Do you still "
                  f"want to delete the stack with cluster-id ({args.cluster_id})? [y/N]"
              )
              if val.lower() != "y":
                  print("Delete cancelled.")
                  return
  
          try:
              aws.delete(args.cluster_id, boto3_session)
          except NoCredentialsError:
              error_no_credentials()
          except Exception:
              raise CliError(
                  "Stack Deletion Failed. Check the AWS CloudFormation Console for details.",
              )
  
          print("Delete Successful")
          return
  
      if (args.cpu_env_image and not args.gpu_env_image) or (
          args.gpu_env_image and not args.cpu_env_image
      ):
          raise CliError(
              "If a CPU or GPU environment image is specified, both should be."
          )
  
      if (
          args.deployment_type != constants.deployment_types.SIMPLE
          or args.deployment_type
          != constants.deployment_types.SIMPLE_RDS
      ):
          if args.agent_subnet_id is not None:
              raise ValueError(
                  f"The agent-subnet-id can only be set if the deployment-type=simple. "
                  f"The agent-subnet-id was set to '{args.agent_subnet_id}', but the "
                  f"deployment-type={args.deployment_type}."
              )
  
      if args.deployment_type == constants.deployment_types.GOVCLOUD:
          if args.region not in ["us-gov-east-1", "us-gov-west-1"]:
              raise ValueError(
                  "When deploying to GovCloud, set the region to either us-gov-east-1 "
                  "or us-gov-west-1."
              )
  
      if args.deployment_type != constants.deployment_types.SIMPLE_RDS:
          if (
              args.db_instance_type
              != constants.defaults.DB_INSTANCE_TYPE
          ):
              raise ValueError(
                  f"--db-instance-size cannot be specified for deployment types other than "
                  f"{constants.deployment_types.SIMPLE_RDS} got {args.deployment_type}"
              )
          if args.db_size != constants.defaults.DB_SIZE:
              raise ValueError(
                  f"--db-size cannot be specified for deployment types other than "
                  f"{constants.deployment_types.SIMPLE_RDS} got {args.deployment_type}"
              )
          if args.db_snapshot != constants.defaults.DB_SNAPSHOT:
              raise ValueError(
                  f"--db-snapshot cannot be specified for deployment types other than "
                  f"{constants.deployment_types.SIMPLE_RDS} got {args.deployment_type}"
              )
      else:
          if args.db_size is not None and args.db_size < 20:
              raise ValueError(
                  "--db-size must be greater than or equal to 20 GB"
              )
  
          if (
              args.db_snapshot is not None
              and args.db_password != constants.defaults.DB_PASSWORD
          ):
              # this precedence is implemented in the deployment template
              print(
                  "--db-snapshot and --db-password are mutually exclusive, "
                  "password value ignored as snapshot would take precedence"
              )
  
      if args.deployment_type != constants.deployment_types.GENAI:
          if args.genai_version is not None:
              raise ValueError(
                  "--genai-version can only be specified for 'genai' deployments"
              )
      else:
          print(
              colored(
                  "GenAI deployment type is experimental and not ready for production use.",
                  "yellow",
              )
          )
          if (
              args.genai_version is not None
              and is_full_git_commit_hash(args.genai_version)
          ):
              short_hash = args.genai_version[:7]
              print(
                  colored(
                      f"GenAI tags are not full commit hashes. Using {short_hash} instead.",
                      "yellow",
                  )
              )
              args.genai_version = short_hash
  
      if args.deployment_type not in {
          constants.deployment_types.EFS,
          constants.deployment_types.GENAI,
      }:
          if args.efs_id is not None:
              raise ValueError(
                  "--efs-id can only be specified for 'efs' deployments"
              )
  
      if args.deployment_type != constants.deployment_types.FSX:
          if args.fsx_id is not None:
              raise ValueError(
                  "--fsx-id can only be specified for 'fsx' deployments"
              )
  
      master_tls_cert = master_tls_key = ""
      if args.master_tls_cert:
          with open(args.master_tls_cert, "rb") as f:
              master_tls_cert = base64.b64encode(f.read()).decode()
      if args.master_tls_key:
          with open(args.master_tls_key, "rb") as f:
              master_tls_key = base64.b64encode(f.read()).decode()
  
      config_file_contents = {}
  
      if args.shut_down_on_connection_loss:
          config_file_contents["hooks"] = {
              "on_connection_lost": ["shutdown", "now"]
          }
  
      master_image_name, agent_image_name = (
          "determined-master",
          "determined-agent",
      )
      if args.enterprise_edition:
          master_image_name, agent_image_name = (
              "hpe-mlde-master",
              "hpe-mlde-agent",
          )
  
      det_configs = {
          constants.cloudformation.KEYPAIR: args.keypair,
          constants.cloudformation.ENABLE_CORS: args.enable_cors,
          constants.cloudformation.MASTER_TLS_CERT: master_tls_cert,
          constants.cloudformation.MASTER_TLS_KEY: master_tls_key,
          constants.cloudformation.MASTER_CERT_NAME: args.master_cert_name,
          constants.cloudformation.MASTER_INSTANCE_TYPE: args.master_instance_type,
          constants.cloudformation.AUX_AGENT_INSTANCE_TYPE: args.aux_agent_instance_type,
          constants.cloudformation.COMPUTE_AGENT_INSTANCE_TYPE: args.compute_agent_instance_type,
          constants.cloudformation.CLUSTER_ID: args.cluster_id,
          constants.cloudformation.EXTRA_TAGS: args.add_tag,
          constants.cloudformation.BOTO3_SESSION: boto3_session,
          constants.cloudformation.VERSION: args.det_version,
          constants.cloudformation.INBOUND_CIDR: args.inbound_cidr,
          constants.cloudformation.DB_PASSWORD: args.db_password,
          constants.cloudformation.DB_INSTANCE_TYPE: args.db_instance_type,
          constants.cloudformation.DB_SNAPSHOT: args.db_snapshot,
          constants.cloudformation.DB_SIZE: args.db_size,
          constants.cloudformation.MAX_IDLE_AGENT_PERIOD: args.max_idle_agent_period,
          constants.cloudformation.MAX_AGENT_STARTING_PERIOD: args.max_agent_starting_period,
          constants.cloudformation.MAX_AUX_CONTAINERS_PER_AGENT: args.max_aux_containers_per_agent,
          constants.cloudformation.MIN_DYNAMIC_AGENTS: args.min_dynamic_agents,
          constants.cloudformation.MAX_DYNAMIC_AGENTS: args.max_dynamic_agents,
          constants.cloudformation.SPOT_ENABLED: args.spot,
          constants.cloudformation.SPOT_MAX_PRICE: args.spot_max_price,
          constants.cloudformation.SUBNET_ID_KEY: args.agent_subnet_id,
          constants.cloudformation.SCHEDULER_TYPE: args.scheduler_type,
          constants.cloudformation.PREEMPTION_ENABLED: args.preemption_enabled,
          constants.cloudformation.CPU_ENV_IMAGE: args.cpu_env_image,
          constants.cloudformation.GPU_ENV_IMAGE: args.gpu_env_image,
          constants.cloudformation.LOG_GROUP_PREFIX: args.log_group_prefix,
          constants.cloudformation.RETAIN_LOG_GROUP: args.retain_log_group,
          constants.cloudformation.IMAGE_REPO_PREFIX: args.image_repo_prefix,
          constants.cloudformation.MOUNT_EFS_ID: args.efs_id,
          constants.cloudformation.MOUNT_FSX_ID: args.fsx_id,
          constants.cloudformation.AGENT_REATTACH_ENABLED: args.agent_reattach_enabled,
          constants.cloudformation.AGENT_RECONNECT_ATTEMPTS: args.agent_reconnect_attempts,
          constants.cloudformation.AGENT_RECONNECT_BACKOFF: args.agent_reconnect_backoff,
          constants.cloudformation.AGENT_CONFIG_FILE_CONTENTS: json.dumps(
              config_file_contents
          ),
          constants.cloudformation.MASTER_IMAGE_NAME: master_image_name,
          constants.cloudformation.AGENT_IMAGE_NAME: agent_image_name,
          constants.cloudformation.DOCKER_USER: args.docker_user,
          constants.cloudformation.DOCKER_PASS: args.docker_pass,
          constants.cloudformation.NOTEBOOK_TIMEOUT: args.notebook_timeout,
          constants.cloudformation.GENAI_VERSION: args.genai_version,
      }
  
      if args.master_config_template_path:
          if not args.master_config_template_path.exists():
              raise ValueError(
                  f"Input master config template doesn't exist: {args.master_config_template_path}"
              )
          with args.master_config_template_path.open("r") as fin:
              det_configs[
                  constants.cloudformation.MASTER_CONFIG_TEMPLATE
              ] = fin.read()
  
      deployment_object = get_deployment_class(args.deployment_type)(
          det_configs
      )
  
      if not args.no_preflight_checks:
          check_quotas(det_configs, deployment_object)
  
      print("Starting Determined Deployment")
      try:
          deployment_object.deploy(
              args.yes, args.update_terminate_agents
          )
      except NoCredentialsError:
          error_no_credentials()
      except Exception as e:
          raise CliError(
              f"Stack Deployment Failed: {e}\nCheck the AWS CloudFormation Console for details.",
          )
  
      if not args.no_wait_for_master:
          try:
              deployment_object.wait_for_master(timeout=5 * 60)
          except MasterTimeoutExpired:
              print(
                  colored(
                      "Determined cluster has been deployed, but master health check has failed.",
                      "red",
                  )
              )
              raise CliError(
                  "For details, SSH to master instance and check /var/log/cloud-init-output.log."
              )
  
      if args.deployment_type == constants.deployment_types.GENAI:
          assert isinstance(deployment_object, vpc.Lore)
          try:
              deployment_object.wait_for_genai(timeout=5 * 60)
          except MasterTimeoutExpired:
              print(
                  colored(
                      "Determined cluster has been deployed, but GenAI health check has failed.",
                      "red",
                  )
              )
              raise CliError(
                  "For details, SSH to master instance and check /var/log/cloud-init-output.log."
              )
  
      print("Determined Deployment Successful")
  
imports: import argparse
  import base64
  import json
  import re
  from pathlib import Path
  from typing import Callable, Dict, Tuple, Type
  import boto3
  from botocore.exceptions import NoCredentialsError
  from termcolor import colored
  from determined.cli.errors import CliError
  from determined.common.declarative_argparse import Arg, ArgGroup, BoolOptArg, Cmd
  from determined.deploy.aws import aws, constants
  from determined.deploy.errors import MasterTimeoutExpired
  from .deployment_types import base, govcloud, secure, simple, vpc
  from .preflight import check_quotas, get_default_cf_parameter
label_desc: Use image node_id 6 for calling a global function with example usage: deploy_aws(command, args) without return types