code: def run_commands_on_ec2_instance(ec2_connection, is_gpu):
      """
      This function assumes that the required 'serve' folder is already available on the ec2 instance in the home directory.
      Returns a map of the command executed and return value of that command.
      """
  
      command_result_map = {}
  
      virtual_env_name = "venv"
  
      with ec2_connection.cd(f"/home/ubuntu/serve"):
          ec2_connection.run(f"python -m venv {virtual_env_name}")
          with ec2_connection.prefix(
              f"source {virtual_env_name}/bin/activate"
          ):
              commands_list = (
                  GPU_INSTANCE_COMMANDS_LIST
                  if is_gpu
                  else CPU_INSTANCE_COMMANDS_LIST
              )
  
              for command in commands_list:
                  LOGGER.info(
                      f"*** Executing command on ec2 instance: {command}"
                  )
                  ret_obj = ec2_connection.run(
                      command,
                      echo=True,
                      warn=True,
                      shell="/bin/bash",
                      env={
                          "LC_CTYPE": "en_US.utf8",
                          "JAVA_HOME": "/usr/lib/jvm/java-11-openjdk-amd64",
                          "PYTHONIOENCODING": "utf8",
                      },
                      encoding="utf8",
                  )
  
                  if ret_obj.return_code != 0:
                      LOGGER.error(f"*** Failed command: {command}")
                      LOGGER.error(
                          f"*** Failed command stdout: {ret_obj.stdout}"
                      )
                      LOGGER.error(
                          f"*** Failed command stderr: {ret_obj.stderr}"
                      )
  
                  command_result_map[command] = ret_obj.return_code
  
      return command_result_map
  
file_path: serve/ci/launcher/launch_test.py
imports: import argparse
  import boto3
  import datetime
  import random
  import subprocess
  import os
  import time
  from botocore.config import Config
  from fabric2 import Connection
  from invoke import run
  from utils import LOGGER, GPU_INSTANCES
  from utils import ec2
label_desc: Use image node_id 1 for calling a global function with example usage: run_commands_on_ec2_instance(ec2_connection, is_gpu) and returns: command_result_map