# Buggy code
def query(params=None):
    """
    Make a web call to aliyun ECS REST API
    """
    path = "https://ecs-cn-hangzhou.aliyuncs.com"

    access_key_id = config.get_cloud_config_value(
        "id", get_configured_provider(), __opts__, search_global=False
    )
    access_key_secret = config.get_cloud_config_value(
        "key", get_configured_provider(), __opts__, search_global=False
    )

    timestamp = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())

    # public interface parameters
    parameters = {
        "Format": "JSON",
        "Version": DEFAULT_ALIYUN_API_VERSION,
        "AccessKeyId": access_key_id,
        "SignatureVersion": "1.0",
        "SignatureMethod": "HMAC-SHA1",
        "SignatureNonce": six.text_type(uuid.uuid1()),
        "TimeStamp": timestamp,
    }

    # include action or function parameters
    if params:
        parameters.update(params)

    # Calculate the string for Signature
    signature = _compute_signature(parameters, access_key_secret)
    parameters["Signature"] = signature

    request = requests.get(path, params=parameters, verify=True)
    if request.status_code != 200:
        raise SaltCloudSystemExit(
            "An error occurred while querying aliyun ECS. HTTP Code: {0}  "
            "Error: '{1}'".format(request.status_code, request.text)
        )

    log.debug(request.url)

    content = request.text

    result = salt.utils.json.loads(content, object_hook=salt.utils.data.encode_dict)
    if "Code" in result:
        raise SaltCloudSystemExit(pprint.pformat(result.get("Message", {})))
    return result


# Traceback (KeyError)
ssh:
----------
ID: echo
Function: cmd.run
Name: echo 'This is a test!'
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/var/tmp/.root_62a99a_salt/py3/salt/state.py", line 1905, in call
**cdata['kwargs'])
File "/var/tmp/.root_62a99a_salt/py3/salt/loader.py", line 1822, in wrapper
return f(*args, **kwargs)
File "/var/tmp/.root_62a99a_salt/py3/salt/states/cmd.py", line 865, in run
'shell': shell or __grains__['shell'],
File "/var/tmp/.root_62a99a_salt/py3/salt/utils/context.py", line 228, in __getitem__
return self._dict()[key]
KeyError: 'shell'
Started: 19:56:36.251433
Duration: 6.909 ms
Changes:

# Fixed code
def query(params=None):
    """
    Make a web call to aliyun ECS REST API
    """
    path = "https://ecs-cn-hangzhou.aliyuncs.com"

    access_key_id = config.get_cloud_config_value(
        "id", get_configured_provider(), __opts__, search_global=False
    )
    access_key_secret = config.get_cloud_config_value(
        "key", get_configured_provider(), __opts__, search_global=False
    )

    timestamp = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())

    # public interface parameters
    parameters = {
        "Format": "JSON",
        "Version": DEFAULT_ALIYUN_API_VERSION,
        "AccessKeyId": access_key_id,
        "SignatureVersion": "1.0",
        "SignatureMethod": "HMAC-SHA1",
        "SignatureNonce": six.text_type(uuid.uuid1()),
        "TimeStamp": timestamp,
    }

    # include action or function parameters
    if params:
        parameters.update(params)

    # Calculate the string for Signature
    signature = _compute_signature(parameters, access_key_secret)
    parameters["Signature"] = signature

    request = requests.get(path, params=parameters, verify=True)
    if request.status_code != 200:
        raise SaltCloudSystemExit(
            "An error occurred while querying aliyun ECS. HTTP Code: {0}  "
            "Error: '{1}'".format(request.status_code, request.text)
        )

    log.debug(request.url)

    content = request.text

    result = salt.utils.json.loads(content)
    if "Code" in result:
        raise SaltCloudSystemExit(pprint.pformat(result.get("Message", {})))
    return result