'Encodes a dictionary to an opaque string.
:type token: dict
:param token: A dictionary containing pagination information,
particularly the service pagination token(s) but also other boto
metadata.
:rtype: str
:returns: An opaque string'

def encode(self, token):

    try:
        json_string = json.dumps(token)
    except (TypeError, UnicodeDecodeError):
        (encoded_token, encoded_keys) = self._encode(token, [])
        encoded_token['boto_encoded_keys'] = encoded_keys
        json_string = json.dumps(encoded_token)
    return base64.b64encode(json_string.encode('utf-8')).decode('utf-8')
