AWS TimeStream Python SDK:无法创建正确的客户端对象

AWS TimeStream Python SDK: Cannot create a correct client object

根据 Python 的 AWS TimeStream SDK 文档,我有以下代码:

import boto3

def list_databases(self):
        print("Listing databases")
        try:
            result = self.client.list_databases(MaxResults=5)
            self._print_databases(result['Databases'])
            next_token = result.get('NextToken', None)
            while next_token:
                result = self.client.list_databases(NextToken=next_token, MaxResults=5)
                self._print_databases(result['Databases'])
                next_token = result.get('NextToken', None)
        except Exception as err:
            print("List databases failed:", err)

session = boto3.Session(profile_name='superuser', region_name='eu-west-1')
query_client = session.client('timestream-query')

list_databases(query_client)

我的用户 superuser 的身份验证似乎工作正常,但用于我的 query_clientboto3 会话没有客户端对象:

Listing databases
List databases failed: 'TimestreamQuery' object has no attribute 'client'

我错过了什么?

此方法中的参数名称可能是错误的:

# this name is discouraged in non-OO code:
def list_databases(self):

self通常用于面向对象的python代码中,这里不是这种情况。

重命名如下:

# this is better:
def list_databases(client):

然后,删除函数体中任何提到的 self,例如:

# this is incorrect:
result = self.client.list_databases(MaxResults=5)

应该是:

# this should work:
result = client.list_databases(MaxResults=5)