botocore.exceptions.ClientError: 调用 ListObjectsV2 操作时发生错误 (InvalidToken)

botocore.exceptions.ClientError: 调用 ListObjectsV2 操作时发生错误 (InvalidToken)

我有一台mlflow托管在 上的服务器aws,它s3在后台用于存储。我正在尝试运行一个lambda-function运行 Python 脚本的程序,该脚本访问mlflow服务器、加载pytorch模型、进行预测并完成。出现问题的代码是:

with open('./data/api_keys.json', 'r') as f:
    API_KEYS = json.load(f)

os.environ['AWS_DEFAULT_REGION'] = API_KEYS['AWS_DEFAULT_REGION']
os.environ["AWS_ACCESS_KEY_ID"] = API_KEYS['AWS_ACCESS_KEY_ID']
os.environ["AWS_SECRET_ACCESS_KEY"] = API_KEYS['AWS_SECRET_ACCESS_KEY']

mlflow.set_tracking_uri(MLFLOW_TRACKING_URI)

model = mlflow.pytorch.load_model(MODEL_URI)     # <---- error thrown here

回溯来自cloudwatch

File "/app/production_script.py", line 26, in <module>
model = mlflow.pytorch.load_model(MODEL_URI)
File "/usr/local/lib/python3.9/site-packages/mlflow/pytorch/__init__.py", line 693, in load_model
local_model_path = _download_artifact_from_uri(artifact_uri=model_uri)
File "/usr/local/lib/python3.9/site-packages/mlflow/tracking/artifact_utils.py", line 95, in _download_artifact_from_uri
return get_artifact_repository(artifact_uri=root_uri).download_artifacts(
File "/usr/local/lib/python3.9/site-packages/mlflow/store/artifact/artifact_repo.py", line 179, in download_artifacts
if self._is_directory(artifact_path):
File "/usr/local/lib/python3.9/site-packages/mlflow/store/artifact/artifact_repo.py", line 61, in _is_directory
listing = self.list_artifacts(artifact_path)
File "/usr/local/lib/python3.9/site-packages/mlflow/store/artifact/s3_artifact_repo.py", line 121, in list_artifacts
for result in results:
File "/usr/local/lib/python3.9/site-packages/botocore/paginate.py", line 269, in __iter__
response = self._make_request(current_kwargs)
File "/usr/local/lib/python3.9/site-packages/botocore/paginate.py", line 357, in _make_request
return self._method(**current_kwargs)
File "/usr/local/lib/python3.9/site-packages/botocore/client.py", line 530, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.9/site-packages/botocore/client.py", line 960, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidToken) when calling the ListObjectsV2 operation: The provided token is malformed or otherwise invalid.

根据文档ListObjectsV2

每次请求都返回存储桶中的部分或全部(最多 1,000 个)对象。

要使用此操作,您必须具有该存储桶的读取访问权限。

要在 AWS Identity and Access Management (IAM) 策略中使用此操作,您必须具有执行 s3:ListBucket 操作的权限。

在我policy为此定义的中lambda-function,我有托管在的存储s3:ListBucket桶的权限mlflow

欢迎提出任何关于如何解决此问题的想法。

相关内容