如何编写Lambda处理程序以将数据发送到Elasticsearch [英] How to write a lambda handler to send the data to Elasticsearch
本文介绍了如何编写Lambda处理程序以将数据发送到Elasticsearch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是将数据发送到本地的Elasticsearch的代码
Below is the code to send the data to Elasticsearch in local
r = [{'Name': 'Dr. Christopher DeSimone', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Tajwar Aamir (Aamir)', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Bernard M. Aaron', 'Specialised and Location': 'Health'},
{'Name': 'Eliana M. Aaron', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Joseph J. Aaron', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Michael R. Aaron', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Darryl H. Aarons', 'Specialised and Location': 'Health'},
{'Name': 'Dr. William B. Aarons', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Sirike T. Aasmaa', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Jacobo A. Abadi', 'Specialised and Location': 'Health'}]
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.cluster.health()
es.indices.create(index='my-index', ignore=400)
for e in enumerate(r):
es.index(index="my-index", body=e[1])
如何使用lambda处理程序将数据发送到AWS的Elasticsearch
How to send the data to Elasticsearch of AWS using lambda handler
我已经创建了Elasticsearch的域公共访问权限(t2小)https://search-xxx.us-east-1.es.amazonaws.com
I have create a domain public access of Elasticsearch(t2 small) https://search-xxx.us-east-1.es.amazonaws.com
如何编写lambda处理程序以将数据发送到弹性搜索
How to write a lambda handler to send the data to elastic search
推荐答案
from requests_aws4auth import AWS4Auth
from elasticsearch import Elasticsearch, RequestsHttpConnection
session = boto3.session.Session()
credentials = session.get_credentials()
awsauth = AWS4Auth(credentials.access_key,
credentials.secret_key,
session.region_name, 'es',
session_token=credentials.token)
es = Elasticsearch(
['https://search-xxx.us-east-1.es.amazonaws.com'],
http_auth=awsauth,
use_ssl=True,
verify_certs=True,
connection_class=RequestsHttpConnection
)
def lambda_handler(event, context):
es.cluster.health()
es.indices.create(index='my-index', ignore=400)
r = [{'Name': 'Dr. Christopher DeSimone', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Tajwar Aamir (Aamir)', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Bernard M. Aaron', 'Specialised and Location': 'Health'},
{'Name': 'Eliana M. Aaron', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Joseph J. Aaron', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Michael R. Aaron', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Darryl H. Aarons', 'Specialised and Location': 'Health'},
{'Name': 'Dr. William B. Aarons', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Sirike T. Aasmaa', 'Specialised and Location': 'Health'},
{'Name': 'Dr. Jacobo A. Abadi', 'Specialised and Location': 'Health'}]
for e in enumerate(r):
es.index(index="my-index", body=e[1])
这篇关于如何编写Lambda处理程序以将数据发送到Elasticsearch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文