【问题标题】:logs data to elasticsearch server将数据记录到 elasticsearch 服务器
【发布时间】:2019-11-27 14:37:02
【问题描述】:

我按照文章“使用 Amazon Rekognition 和 Amazon Athena 探索社交媒体上的图像”进行了操作,一切正常。

https://aws.amazon.com/blogs/machine-learning/exploring-images-on-social-media-using-amazon-rekognition-and-amazon-athena/

我的问题是:如何将数据流式传输到 elasticsearch 服务?

我尝试在函数中添加这段代码

import base64
import requests
from requests_aws4auth import AWS4Auth

host = '' # the Amazon ES domain, including https://
index = 'lambda-kine-index'
type = 'lambda-kine-type'
url = host + '/' + index + '/' + type + '/'

headers = { "Content-Type": "application/json" }

region = 'us-east-1' # e.g. us-west-1
service = 'es'
credentials = boto3.Session().get_credentials()
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)

# edit the function
        r = requests.put(url + tweet['id'], auth=awsauth, json=json.dumps(sentiment_record), headers=headers)

函数下载自:

https://s3.amazonaws.com/aws-bigdata-blog/artifacts/EyeOfCustomer/labelimage.zip

问题是请求模块不是内置的。我不知道如何在这个函数中添加它。 但是我想知道在这种情况下是否有任何其他方法可以将数据添加到elasticsearch。

【问题讨论】:

  • 尝试使用 - from botocore.vendored import requests 代替 import requests

标签: amazon-web-services elasticsearch aws-lambda


【解决方案1】:

按照 cmets 中的建议从 botocore 导入请求不起作用。但是以下代码一旦添加到 lambda 函数就可以工作。

import urllib3
http = urllib3.PoolManager()
host_senti = 'https://search-xxx.us-east-1.es.amazonaws.com/mysentiments/senti/'

# The line to actually add an entry to elastic
        http.request('POST', host_senti+str(tweet['id']), headers = {'Content-Type': 'application/json'}, body = json.dumps(sentiment_record) )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    相关资源
    最近更新 更多