使用 python 弹性搜索包访问基于 aws 弹性搜索角色

时间:2021-04-19 06:58:21

标签: python elasticsearch huggingface-transformers aws-elasticsearch haystack

我正在使用 deepset/haystack 并与弹性搜索通信。使用 OpenDistroElasticsearchDocumentStore 方法可以很好地使用用户名、密码访问 aws 弹性搜索。在 ec2 中部署时,似乎不适用于基于角色的访问。请建议我使用 python 弹性搜索包访问 aws 弹性搜索的解决方案,并提供角色访问

1 个答案:

答案 0 :(得分:0)

您是指 AWS 上基于 IAM 的访问,例如 this?我们最近刚刚合并了一项可能对您有所帮助的功能 (#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")
相关问题