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

2024-10-01 00:21:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用deepset/haystack并与弹性搜索进行通信。使用OpenDistributoLasticSearchDocumentStore方法可以很好地使用用户名、pasword访问aws弹性搜索。在ec2中部署时,似乎无法使用基于角色的访问。请向我推荐一个解决方案,在给定角色访问权限的情况下,使用python弹性搜索包访问aws弹性搜索


Tags: 方法aws权限角色部署情况解决方案ec2
1条回答
网友
1楼 · 发布于 2024-10-01 00:21:05

你是说像this这样基于IAM的AWS访问吗?我们最近刚刚合并了一个功能,这可能会对您有所帮助(#965)。请从master branch安装最新的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")

相关问题 更多 >