def make_spot_fleet_cluster(<EOL>security_groupid,<EOL>subnet_id,<EOL>keypair_name,<EOL>iam_instance_profile_arn,<EOL>spot_fleet_iam_role,<EOL>target_capacity=<NUM_LIT:20>,<EOL>spot_price=<NUM_LIT>,<EOL>expires_days=<NUM_LIT:7>,<EOL>allocation_strategy='<STR_LIT>',<EOL>instance_types=SPOT_INSTANCE_TYPES,<EOL>instance_weights=None,<EOL>instance_ami='<STR_LIT>',<EOL>instance_user_data=None,<EOL>instance_ebs_optimized=True,<EOL>wait_until_up=True,<EOL>client=None,<EOL>raiseonfail=False<EOL>):
fleetconfig = copy.deepcopy(SPOT_FLEET_CONFIG)<EOL>fleetconfig['<STR_LIT>'] = spot_fleet_iam_role<EOL>fleetconfig['<STR_LIT>'] = allocation_strategy<EOL>fleetconfig['<STR_LIT>'] = target_capacity<EOL>fleetconfig['<STR_LIT>'] = str(spot_price)<EOL>fleetconfig['<STR_LIT>'] = (<EOL>datetime.utcnow() + timedelta(days=expires_days)<EOL>).strftime(<EOL>'<STR_LIT>'<EOL>)<EOL>if (isinstance(instance_user_data, str) and<EOL>os.path.exists(instance_user_data)):<EOL><INDENT>with open(instance_user_data,'<STR_LIT:rb>') as infd:<EOL><INDENT>udata = base64.b64encode(infd.read()).decode()<EOL><DEDENT><DEDENT>elif isinstance(instance_user_data, str):<EOL><INDENT>udata = base64.b64encode(instance_user_data.encode()).decode()<EOL><DEDENT>else:<EOL><INDENT>udata = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % datetime.utcnow().isoformat()<EOL>)<EOL>udata = base64.b64encode(udata.encode()).decode()<EOL><DEDENT>for ind, itype in enumerate(instance_types):<EOL><INDENT>thisinstance = SPOT_PERINSTANCE_CONFIG.copy()<EOL>thisinstance['<STR_LIT>'] = itype<EOL>thisinstance['<STR_LIT>'] = instance_ami<EOL>thisinstance['<STR_LIT>'] = subnet_id<EOL>thisinstance['<STR_LIT>'] = keypair_name<EOL>thisinstance['<STR_LIT>']['<STR_LIT>'] = iam_instance_profile_arn<EOL>thisinstance['<STR_LIT>'][<NUM_LIT:0>] = {'<STR_LIT>':security_groupid}<EOL>thisinstance['<STR_LIT>'] = udata<EOL>thisinstance['<STR_LIT>'] = instance_ebs_optimized<EOL>if isinstance(instance_weights, list):<EOL><INDENT>thisinstance['<STR_LIT>'] = instance_weights[ind]<EOL><DEDENT>fleetconfig['<STR_LIT>'].append(thisinstance)<EOL><DEDENT>if not client:<EOL><INDENT>client = boto3.client('<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>resp = client.request_spot_fleet(<EOL>SpotFleetRequestConfig=fleetconfig,<EOL>)<EOL>if not resp:<EOL><INDENT>LOGERROR('<STR_LIT>')<EOL>return None<EOL><DEDENT>else:<EOL><INDENT>spot_fleet_reqid = resp['<STR_LIT>']<EOL>LOGINFO('<STR_LIT>' %<EOL>spot_fleet_reqid)<EOL>if not wait_until_up:<EOL><INDENT>return spot_fleet_reqid<EOL><DEDENT>else:<EOL><INDENT>ntries = <NUM_LIT:10><EOL>curr_try = <NUM_LIT:0><EOL>while curr_try < ntries:<EOL><INDENT>resp = client.describe_spot_fleet_requests(<EOL>SpotFleetRequestIds=[<EOL>spot_fleet_reqid<EOL>]<EOL>)<EOL>curr_state = resp.get('<STR_LIT>',[])<EOL>if len(curr_state) > <NUM_LIT:0>:<EOL><INDENT>curr_state = curr_state[<NUM_LIT:0>]['<STR_LIT>']<EOL>if curr_state == '<STR_LIT>':<EOL><INDENT>LOGINFO('<STR_LIT>' %<EOL>spot_fleet_reqid)<EOL>break<EOL><DEDENT><DEDENT>LOGINFO(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (curr_try, ntries)<EOL>)<EOL>curr_try = curr_try + <NUM_LIT:1><EOL>time.sleep(<NUM_LIT>)<EOL><DEDENT>return spot_fleet_reqid<EOL><DEDENT><DEDENT><DEDENT>except ClientError as e:<EOL><INDENT>LOGEXCEPTION('<STR_LIT>')<EOL>if raiseonfail:<EOL><INDENT>raise<EOL><DEDENT>return None<EOL><DEDENT>except Exception as e:<EOL><INDENT>LOGEXCEPTION('<STR_LIT>')<EOL>if raiseonfail:<EOL><INDENT>raise<EOL><DEDENT>return None<EOL><DEDENT>
This makes an EC2 spot-fleet cluster.

    This requires a security group ID attached to a VPC config and subnet, a
    keypair generated beforehand, and an IAM role ARN for the instance. See:

    https://docs.aws.amazon.com/cli/latest/userguide/tutorial-ec2-ubuntu.html

    Use `user_data` to launch tasks on instance launch.

    Parameters
    ----------

    security_groupid : str
        The security group ID of the AWS VPC where the instances will be
        launched.

    subnet_id : str
        The subnet ID of the AWS VPC where the instances will be
        launched.

    keypair_name : str
        The name of the keypair to be used to allow SSH access to all instances
        launched here. This corresponds to an already downloaded AWS keypair PEM
        file.

    iam_instance_profile_arn : str
        The ARN string corresponding to the AWS instance profile that describes
        the permissions the launched instances have to access other AWS
        resources. Set this up in AWS IAM.

    spot_fleet_iam_role : str
        This is the name of AWS IAM role that allows the Spot Fleet Manager to
        scale up and down instances based on demand and instances failing,
        etc. Set this up in IAM.

    target_capacity : int
        The number of instances to target in the fleet request. The fleet
        manager service will attempt to maintain this number over the lifetime
        of the Spot Fleet Request.

    spot_price : float
        The bid price in USD for the instances. This is per hour. Keep this at
        about half the hourly on-demand price of the desired instances to make
        sure your instances aren't taken away by AWS when it needs capacity.

    expires_days : int
        The number of days this request is active for. All instances launched by
        this request will live at least this long and will be terminated
        automatically after.

    allocation_strategy : {'lowestPrice', 'diversified'}
        The allocation strategy used by the fleet manager.

    instance_types : list of str
        List of the instance type to launch. See the following URL for a list of
        IDs: https://aws.amazon.com/ec2/pricing/on-demand/

    instance_weights : list of float or None
        If `instance_types` is a list of different instance types, this is the
        relative weight applied towards launching each instance type. This can
        be used to launch a mix of instances in a defined ratio among their
        types. Doing this can make the spot fleet more resilient to AWS taking
        back the instances if it runs out of capacity.

    instance_ami : str
        The Amazon Machine Image ID that describes the OS the instances will use
        after launch. The default ID is Amazon Linux 2 in the US East region.

    instance_user_data : str or None
        This is either the path to a file on disk that contains a shell-script
        or a string containing a shell-script that will be executed by root
        right after the instance is launched. Use to automatically set up
        workers and queues. If None, will not execute anything at instance
        start up.

    instance_ebs_optimized : bool
        If True, will enable EBS optimization to speed up IO. This is usually
        True for all instances made available in the last couple of years.

    wait_until_up : bool
        If True, will not return from this function until the spot fleet request
        is acknowledged by AWS.

    client : boto3.Client or None
        If None, this function will instantiate a new `boto3.Client` object to
        use in its operations. Alternatively, pass in an existing `boto3.Client`
        instance to re-use it here.

    raiseonfail : bool
        If True, will re-raise whatever Exception caused the operation to fail
        and break out immediately.

    Returns
    -------

    str or None
        This is the spot fleet request ID if successful. Otherwise, returns
        None.