Skip to content

Athena

AthenaReader #

Bases: BaseReader

阿泰娜读取器。

遵循AWS安全最佳实践。 AWS不建议在代码中硬编码凭据。 我们建议您使用IAM角色而不是IAM用户凭据。 如果必须使用凭据,请不要将它们嵌入到您的代码中。 而是将它们存储在环境变量中或单独的配置文件中。

Source code in llama_index/readers/athena/base.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class AthenaReader(BaseReader):
    """阿泰娜读取器。

    遵循AWS安全最佳实践。
    AWS不建议在代码中硬编码凭据。
    我们建议您使用IAM角色而不是IAM用户凭据。
    如果必须使用凭据,请不要将它们嵌入到您的代码中。
    而是将它们存储在环境变量中或单独的配置文件中。"""

    def __init__(
        self,
    ) -> None:
        """使用参数进行初始化。"""

    def create_athena_engine(
        self,
        aws_access_key: Optional[str] = None,
        aws_secret_key: Optional[str] = None,
        aws_region: str = None,
        s3_staging_dir: str = None,
        database: str = None,
        workgroup: str = None,
    ):
        """Args:
aws_access_key是来自AWS凭证的AWS访问密钥
aws_secret_key是来自AWS凭证的AWS秘密密钥
aws_region是AWS区域
s3_staging_dir是S3暂存(结果存储桶)目录
database是Athena数据库名称
workgroup是Athena工作组名称。
"""
        if not aws_access_key or not aws_secret_key:
            conn_str = (
                "awsathena+rest://:@athena.{region_name}.amazonaws.com:443/"
                "{database}?s3_staging_dir={s3_staging_dir}?work_group={workgroup}"
            )

            engine = create_engine(
                conn_str.format(
                    region_name=aws_region,
                    s3_staging_dir=s3_staging_dir,
                    database=database,
                    workgroup=workgroup,
                )
            )

        else:
            warnings.warn(
                "aws_access_key and aws_secret_key are set. We recommend to use IAM role instead."
            )
            boto3.client(
                "athena",
                aws_access_key_id=aws_access_key,
                aws_secret_access_key=aws_secret_key,
                region_name=aws_region,
            )

            conn_str = (
                "awsathena+rest://:@athena.{region_name}.amazonaws.com:443/"
                "{database}?s3_staging_dir={s3_staging_dir}?work_group={workgroup}"
            )

            engine = create_engine(
                conn_str.format(
                    region_name=aws_region,
                    s3_staging_dir=s3_staging_dir,
                    database=database,
                    workgroup=workgroup,
                )
            )
        return engine

create_athena_engine #

create_athena_engine(
    aws_access_key: Optional[str] = None,
    aws_secret_key: Optional[str] = None,
    aws_region: str = None,
    s3_staging_dir: str = None,
    database: str = None,
    workgroup: str = None,
)

Args: aws_access_key是来自AWS凭证的AWS访问密钥 aws_secret_key是来自AWS凭证的AWS秘密密钥 aws_region是AWS区域 s3_staging_dir是S3暂存(结果存储桶)目录 database是Athena数据库名称 workgroup是Athena工作组名称。

Source code in llama_index/readers/athena/base.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    def create_athena_engine(
        self,
        aws_access_key: Optional[str] = None,
        aws_secret_key: Optional[str] = None,
        aws_region: str = None,
        s3_staging_dir: str = None,
        database: str = None,
        workgroup: str = None,
    ):
        """Args:
aws_access_key是来自AWS凭证的AWS访问密钥
aws_secret_key是来自AWS凭证的AWS秘密密钥
aws_region是AWS区域
s3_staging_dir是S3暂存(结果存储桶)目录
database是Athena数据库名称
workgroup是Athena工作组名称。
"""
        if not aws_access_key or not aws_secret_key:
            conn_str = (
                "awsathena+rest://:@athena.{region_name}.amazonaws.com:443/"
                "{database}?s3_staging_dir={s3_staging_dir}?work_group={workgroup}"
            )

            engine = create_engine(
                conn_str.format(
                    region_name=aws_region,
                    s3_staging_dir=s3_staging_dir,
                    database=database,
                    workgroup=workgroup,
                )
            )

        else:
            warnings.warn(
                "aws_access_key and aws_secret_key are set. We recommend to use IAM role instead."
            )
            boto3.client(
                "athena",
                aws_access_key_id=aws_access_key,
                aws_secret_access_key=aws_secret_key,
                region_name=aws_region,
            )

            conn_str = (
                "awsathena+rest://:@athena.{region_name}.amazonaws.com:443/"
                "{database}?s3_staging_dir={s3_staging_dir}?work_group={workgroup}"
            )

            engine = create_engine(
                conn_str.format(
                    region_name=aws_region,
                    s3_staging_dir=s3_staging_dir,
                    database=database,
                    workgroup=workgroup,
                )
            )
        return engine