code: def launch_instance(
      ami_id,
      instance_type,
      ec2_key_name=None,
      region="us-west-2",
      user_data=None,
      iam_instance_profile_name=None,
      instance_name="",
  ):
      """
      Launch an instance
      :param ami_id: AMI ID to be used for launched instance
      :param instance_type: Instance type of launched instance
      :param region: Region where instance will be launched
      :param user_data: Script to run when instance is launched as a str
      :param iam_instance_profile_arn: EC2 Role to be attached
      :param instance_name: Tag to display as Name on EC2 Console
      :return: <dict> Information about the instance that was launched
      """
      if not ami_id:
          raise Exception("No ami_id provided")
      if not ec2_key_name:
          raise Exception("Ec2 Key name must be provided")
      client = boto3.Session(region_name=region).client("ec2")
  
      # Construct the dictionary with the arguments for API call
      arguments_dict = {
          "KeyName": ec2_key_name,
          "ImageId": ami_id,
          "InstanceType": instance_type,
          "MaxCount": 1,
          "MinCount": 1,
          "TagSpecifications": [
              {
                  "ResourceType": "instance",
                  "Tags": [
                      {"Key": "Name", "Value": f"CI-CD {instance_name}"}
                  ],
              },
          ],
          "BlockDeviceMappings": [
              {
                  "DeviceName": "/dev/sda1",
                  "Ebs": {
                      "VolumeSize": 200,
                  },
              }
          ],
      }
  
      if user_data:
          arguments_dict["UserData"] = user_data
      if iam_instance_profile_name:
          arguments_dict["IamInstanceProfile"] = {
              "Name": iam_instance_profile_name
          }
  
      LOGGER.info(
          f"Launching instance with name: {instance_name}, and key: {ec2_key_name}"
      )
  
      response = client.run_instances(**arguments_dict)
  
      if not response or len(response["Instances"]) < 1:
          raise Exception(
              "Unable to launch the instance. Did not return any response"
          )
  
      LOGGER.info(f"Instance launched successfully.")
  
      return response["Instances"][0]
  
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 3 for calling a global function with example usage: launch_instance(ami_id, instance_type, ec2_key_name, region, user_data, iam_instance_profile_name, instance_name) and returns: response