def create_ssh_command(instance_id, instance_name, username, key_file, port, gateway_instance_id):
    ec2 = boto3.resource('ec2')
    if instance_id is not None:
        try:
            instance = ec2.Instance(instance_id)
            hostname = instance.public_ip_address
        except botocore.exceptions.ClientError as e:
            click.echo("Invalid instance ID {0} ({1})".format(instance_id, e), err=True)
            sys.exit(2)
    elif instance_name is not None:
        try:
            condition = {'Name': 'tag:Name', 'Values': [instance_name]}
            instances = ec2.instances.filter(Filters=[condition])
            target_instances = []
            for idx, i in enumerate(instances):
                target_instances.append(i)
                tag_name = get_tag_value(i.tags, 'Name')
                click.echo('[{0}]: {1}\t{2}\t{3}\t{4}'.format(
                    idx, i.id, i.private_ip_address, i.state['Name'], tag_name))
            selected_idx = click.prompt("Please enter a valid number", type=int, default=0)
            # TODO: add validation for if selected_idx exceeds length of target_instances
            click.echo("{0} is selected.".format(selected_idx))
            instance = target_instances[selected_idx]
            if instance.public_ip_address is not None:
                hostname = instance.public_ip_address
            else:
                click.echo("Public IP address not set.  Attempting to use the private IP address.")
                hostname = instance.private_ip_address
        except botocore.exceptions.ClientError as e:
            click.echo("Invalid instance ID {0} ({1})".format(instance_id, e), err=True)
            sys.exit(2)
    # TODO: need to refactor and make it testable
    if gateway_instance_id is not None:
        gateway_instance = ec2.Instance(gateway_instance_id)
        gateway_public_ip = gateway_instance.public_ip_address
        hostname = instance.private_ip_address
        cmd = 'ssh -tt ubuntu@{0} -i {1} -p {2} ssh {3}@{4}'.format(
            gateway_public_ip, key_file, port, username, hostname)
    else:
        cmd = 'ssh {0}@{1} -i {2} -p {3}'.format(username, hostname, key_file, port)
    return cmd
Convert polygons to multipolygons so all features are homogenous in the
dataset/ETHPy150Open achiku/jungle/jungle/ec2.py/create_ssh_command--crossover with--dataset/ETHPy150Open newsapps/django-boundaryservice/boundaryservice/management/commands/loadshapefiles.py/Command.polygon_to_multipolygon