AWS Lambda与弹性搜索交互

2024-10-01 13:43:09 发布

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

我是AWS领域的新手,尝试开发一个概念证明,允许lambda函数与elasticSearch(AWS服务)和s3bucket交互。在

我不知道它是怎么工作的。我们必须设置一个链接到Lambda函数但没有用户的IAM角色,因此第一个问题:

  • 谁是运行Lambda函数的用户?在

我这样设置弹性搜索连接(使用https://github.com/DavidMuller/aws-requests-auth):

def connectES(esEndPoint):
print ('Connecting to the ES Endpoint {0}'.format(esEndPoint))
try:
    # let's talk to our AWS Elasticsearch cluster
    auth = BotoAWSRequestsAuth(
                aws_host='vpc-poc-lambda-3opu7gwdw7bwvtmmazjmdgo7gi.eu-west-3.es.amazonaws.com',
                aws_region='eu-west-3',
                aws_service='es')
    esClient = Elasticsearch(
        hosts=[{'host': esEndPoint, 'port': 443}],
        use_ssl=True,
        verify_certs=True,
        connection_class=RequestsHttpConnection,
        http_auth=auth)
    return esClient
except Exception as E:
    print("Unable to connect to {0}".format(esEndPoint))
    print(E)
    exit(3)

它很好用,但我不明白它用的是什么证书。 然后我成功地创建了一个索引:

^{pr2}$

但当我试图为这样的文档编制索引时,我得到了一个错误:

esClient.index(index='test', doc_type='post', id=123456, body={
            'author': 'John Doe',
            'blog': 'Learning Elasticsearch',
            'title': 'Using Python with Elasticsearch',
            'tags': ['python', 'elasticsearch', 'tips'],
        })


[WARNING]   2018-02-15T10:39:28.460Z    7f1cc69d-123c-11e8-be8b-cbbfad79068b    PUT https://vpc-****-****.eu-west-3.es.amazonaws.com:443/test/post/123456 [status:406 request:0.039s]
Document not indexed
Error:  string indices must be integers

我真的不明白为什么它不能工作,希望有一个简单的方法来与Lambda的其他AWS服务交互。在

你能帮我吗? 谢谢


Tags: tolambda函数comauthawseselasticsearch
1条回答
网友
1楼 · 发布于 2024-10-01 13:43:09

在我一个同事的帮助下,我终于发现了这个问题。 当您尝试在旧版本中使用elastisearch python库而在较新版本中使用elasticsearch服务器时,会出现错误append。 我将lib(https://elasticsearch-py.readthedocs.io/en/master/Changelog.html)升级到最新版本,现在它工作得很好。在

我很抱歉打扰了你,希望这能帮助像我这样的人。在

相关问题 更多 >