You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Great Expectations连接S3存储数据时的凭证配置问题排查

原因分析
  1. 数据连接器与执行引擎职责分离:InferredAssetS3DataConnector的boto3_options仅用于数据资产发现(比如get_available_data_asset_names),而PandasExecutionEngine读取数据时,会直接使用s3fs/boto3的默认凭证链,不会读取数据连接器中的配置,这是导致get_validator报错的核心原因。
  2. CLI命令的配置加载逻辑:great_expectations suite new等CLI工具在执行时,未正确传递数据连接器中的自定义端点配置,导致默认使用AWS S3的官方地址。

解决方法

方法一:在执行引擎中添加S3配置

修改great_expectations.yaml,在PandasExecutionEngine下添加fs_args,将Minio的凭证和端点配置传递给s3fs,确保执行引擎读取数据时使用正确的配置:

datasources:
  s3_datasource:
    module_name: great_expectations.datasource
    execution_engine:
      class_name: PandasExecutionEngine
      module_name: great_expectations.execution_engine
      fs_args:
        s3:
          endpoint_url: http://localhost:9000
          key: minio
          secret: minio
    class_name: Datasource
    data_connectors:
      # 保持原有数据连接器配置不变
      default_runtime_data_connector_name:
        module_name: great_expectations.datasource.data_connector
        class_name: RuntimeDataConnector
        batch_identifiers:
          - default_identifier_name
      default_inferred_data_connector_name:
        prefix: data/
        module_name: great_expectations.datasource.data_connector
        default_regex:
          pattern: (.*)\.csv
          group_names:
            - data_asset_name
        boto3_options:
          endpoint_url: http://localhost:9000
          aws_access_key_id: minio
          aws_secret_access_key: minio
        bucket: ge-bucket
        class_name: InferredAssetS3DataConnector

方法二:设置环境变量

在执行代码或CLI命令前,设置以下环境变量,让boto3和s3fs优先读取这些配置,跳过.aws/config的查找:

export AWS_ACCESS_KEY_ID=minio
export AWS_SECRET_ACCESS_KEY=minio
export AWS_S3_ENDPOINT_URL=http://localhost:9000

方法三:代码中手动指定S3FileSystem

在代码中创建带有Minio配置的S3FileSystem实例,直接传递给执行引擎:

import great_expectations as ge
from great_expectations.core.batch import BatchRequest
from s3fs import S3FileSystem

# 创建自定义S3FileSystem
fs = S3FileSystem(
    endpoint_url="http://localhost:9000",
    key="minio",
    secret="minio"
)

# 加载上下文并替换执行引擎的文件系统
context = ge.data_context.DataContext(context_root_dir="./great_expectations")
context.datasources["s3_datasource"].execution_engine.fs = fs

# 后续代码保持不变
batch_request_parameters = {
 'datasource_name': 's3_datasource',
 'data_connector_name': 'default_inferred_data_connector_name',
 'data_asset_name': 'data/yellow_tripdata_sample_2019-01',
 'limit': 1000
}
batch_request=BatchRequest(**batch_request_parameters)

validator = context.get_validator(
batch_request=batch_request, expectation_suite_name='taxi_demo')

内容的提问来源于stack exchange,提问作者Adil Blanco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 09:20:30