# Buggy code
def create_snapshot(kwargs=None, call=None, wait_to_finish=False):
    """
    Create a snapshot
    """
    if call != "function":
        log.error("The create_snapshot function must be called with -f or --function.")
        return False

    if "volume_id" not in kwargs:
        log.error("A volume_id must be specified to create a snapshot.")
        return False

    if "description" not in kwargs:
        kwargs["description"] = ""

    params = {"Action": "CreateSnapshot"}

    if "volume_id" in kwargs:
        params["VolumeId"] = kwargs["volume_id"]

    if "description" in kwargs:
        params["Description"] = kwargs["description"]

    log.debug(params)

    data = aws.query(
        params,
        return_url=True,
        location=get_location(),
        provider=get_provider(),
        opts=__opts__,
        sigver="4",
    )

    r_data = {}
    for d in data:
        for k, v in d.items():
            r_data[k] = v
    snapshot_id = r_data["snapshotId"]

    # Waits till volume is available
    if wait_to_finish:
        salt.utils.cloud.run_func_until_ret_arg(
            fun=describe_snapshots,
            kwargs={"snapshot_id": snapshot_id},
            fun_call=call,
            argument_being_watched="status",
            required_argument_response="completed",
        )

    return data


# Traceback (AttributeError)
Traceback (most recent call last):
File "/tmp/test.py", line 5, in <module>
snapshot = client.action(fun="create_snapshot", provider="ec2-ireland-test", kwargs={"volume_id": "vol-351d8826", "description": "Test clouds/ec2.py create_snapshot"})
File "/usr/lib/python2.7/site-packages/salt/cloud/__init__.py", line 454, in action
return mapper.do_function(provider, fun, kwargs)
File "/usr/lib/python2.7/site-packages/salt/cloud/__init__.py", line 1496, in do_function
call='function', kwargs=kwargs
File "/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.py", line 3724, in create_snapshot
for k, v in d.items():
AttributeError: 'list' object has no attribute 'items'

# Fixed code
def create_snapshot(kwargs=None, call=None, wait_to_finish=False):
    """
    Create a snapshot.

    volume_id
        The ID of the Volume from which to create a snapshot.

    description
        The optional description of the snapshot.

    CLI Exampe:

    .. code-block:: bash

        salt-cloud -f create_snapshot my-ec2-config volume_id=vol-351d8826
        salt-cloud -f create_snapshot my-ec2-config volume_id=vol-351d8826 \\
            description="My Snapshot Description"
    """
    if call != "function":
        raise SaltCloudSystemExit(
            "The create_snapshot function must be called with -f or --function."
        )

    if kwargs is None:
        kwargs = {}

    volume_id = kwargs.get("volume_id", None)
    description = kwargs.get("description", "")

    if volume_id is None:
        raise SaltCloudSystemExit("A volume_id must be specified to create a snapshot.")

    params = {
        "Action": "CreateSnapshot",
        "VolumeId": volume_id,
        "Description": description,
    }

    log.debug(params)

    data = aws.query(
        params,
        return_url=True,
        return_root=True,
        location=get_location(),
        provider=get_provider(),
        opts=__opts__,
        sigver="4",
    )[0]

    r_data = {}
    for d in data:
        for k, v in d.items():
            r_data[k] = v
    snapshot_id = r_data["snapshotId"]

    # Waits till volume is available
    if wait_to_finish:
        salt.utils.cloud.run_func_until_ret_arg(
            fun=describe_snapshots,
            kwargs={"snapshot_id": snapshot_id},
            fun_call=call,
            argument_being_watched="status",
            required_argument_response="completed",
        )

    return data