【发布时间】:2018-07-26 02:15:46
【问题描述】:
我是 AWS 领域的新手,并尝试开发一个概念证明,允许 lambda 函数与 elasticSearch(AWS 服务)和 S3 存储桶进行交互。
我不确定它是如何工作的。我们必须设置一个与 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)
它似乎可以工作,但我不明白它使用什么凭据。 然后我成功创建了一个索引:
esClient.indices.create('test')
但是当我尝试索引这样的文档时,我得到了错误:
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 服务进行交互。
你能帮帮我吗? 谢谢
【问题讨论】:
-
Amazon ElasticSearch 支持 IAM 凭证。我假设您已将 ES 配置为允许从运行 Lambda 函数的 IAM 角色进行访问。关于“字符串索引”错误,ES 文档建议索引函数的参数是一个字典,如 client.index({ index: 'myindex', type: 'mytype', id: '1', body: { 。 .. },标签:[...] })
标签: python amazon-web-services elasticsearch aws-lambda