def construct_instance_market_options(instancemarket, spotinterruptionbehavior, spotmaxprice):
    """ construct the dictionary necessary to configure instance market selection
    (on-demand vs spot)
    See:
    https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.ServiceResource.create_instances
    and
    https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_InstanceMarketOptionsRequest.html
    """
    instmarkoptions = dict()
    if instancemarket == "spot":
        instmarkoptions['MarketType'] = "spot"
        instmarkoptions['SpotOptions'] = dict()
        if spotmaxprice != "ondemand":
            # no value for MaxPrice means ondemand, so fill it in if spotmaxprice is not ondemand
            instmarkoptions['SpotOptions']['MaxPrice'] = spotmaxprice
        if spotinterruptionbehavior != "terminate":
            # if you have special interruption behavior, we also need to make the instance persistent
            instmarkoptions['SpotOptions']['InstanceInterruptionBehavior'] = spotinterruptionbehavior
            instmarkoptions['SpotOptions']['SpotInstanceType'] = "persistent"
        return instmarkoptions
    elif instancemarket == "ondemand":
        # empty dict = on demand
        return instmarkoptions
    else:
        assert False, "INVALID INSTANCE MARKET TYPE."