code: def terminate_instance(instance_id, region=DEFAULT_REGION):
      """
      Terminate EC2 instances with matching instance ID
      :param instance_id: Instance ID to be terminated
      :param region: Region where instance is located
      """
      if not instance_id:
          raise Exception("No instance id provided")
      client = boto3.Session(region_name=region).client("ec2")
      response = client.terminate_instances(InstanceIds=[instance_id])
      if not response:
          raise Exception(
              "Unable to terminate instance. No response received."
          )
      instances_terminated = response["TerminatingInstances"]
      if not instances_terminated:
          raise Exception("Failed to terminate instance.")
      if instances_terminated[0]["InstanceId"] != instance_id:
          raise Exception(
              "Failed to terminate instance. Unknown error."
          )
  
imports: import boto3
  import os
  import time
  import re
  from inspect import signature
  import random
  from retrying import retry
  from fabric2 import Connection
  from botocore.config import Config
  from botocore.exceptions import ClientError
  from invoke import run
  from invoke.context import Context
  from .None import DEFAULT_REGION, LOGGER
label_desc: Use image node_id 13 for calling a global function with example usage: terminate_instance(instance_id, region) without return types