2

我正在使用deepset/haystack并与弹性搜索进行通信。使用 OpenDistroElasticsearchDocumentStore 方法适用于用户名、密码访问 aws 弹性搜索。在 ec2 中部署时似乎不适用于基于角色的访问。请建议我使用 python 弹性搜索包访问 aws 弹性搜索的解决方案,给定角色访问权限

4

2 回答 2

1

您是指像这样在 AWS 上基于 IAM 的访问吗?我们最近刚刚合并了一个可能对您有所帮助的功能 ( #965 )。请从 master 分支安装最新的 Haystack 版本,然后尝试以下方法:

import boto3

from requests_aws4auth import AWS4Auth
from haystack.document_store.elasticsearch import ElasticsearchDocumentStore
from elasticsearch import RequestsHttpConnection

host = '<vpc_host>'
port = 443
region = 'eu-central-1'
service = 'es'
 
credentials = boto3.Session().get_credentials()
aws4auth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)
 
document_store = OpenDistroElasticsearchDocumentStore(host=host,
                                            port=port,
                                            aws4auth=aws4auth,
                                            # can't be used with default es client version used in e.g. aws sagemaker
                                            embedding_field=None,
                                            index="document")
于 2021-04-20T08:19:00.200 回答
0
from requests_aws4auth import AWS4Auth
from botocore.session import Session
credentials = Session().get_credentials()
auth = AWS4Auth(region='eu-west-1', service='es', refreshable_credentials=credentials)

此示例展示了如何构建一个具有自动刷新凭证的 AWS4Auth 实例,适用于使用 AWS IAM 承担角色的长时间运行的应用程序。RefreshableCredentials 实例用于为每个请求生成有效的静态凭证,从而无需在临时凭证过期时重新创建 AWS4Auth 实例。

来源:https ://github.com/tedder/requests-aws4auth#dynamic-sts-credentials-using-botocore-refreshablecredentials

它于2021 年 5 月合并到 AWS4Auth 中

于 2022-02-11T20:38:43.427 回答