问题描述
我在 elasticsearch 上遇到了问题。 我终于可以发布到elasticsearch,但数据是用“S”值而不是实际值写入的。
当我查看我的 cloudwatch 日志时,我看到了这一点。
{
"Records":[
{
"eventID":"d5d4955d706dd71348760a482f33735f","eventName":"INSERT","eventVersion":"1.1","eventSource":"aws:dynamodb","awsRegion":"us-east-1","dynamodb":{
"ApproximateCreationDateTime":1613816980.0,"Keys":{
"uuid":{
"S":"c140a68de65301465cd1cd3d97cc4107"
}
},"NewImage":{
"Smsstatus":{
"S":"received"
},"streetname":{
"S":"King tut"
},"timestampMessage":{
"S":"Sat Feb 20 2021 10:29:39 GMT+0000 (Coordinated Universal Time)"
}
}
}
}
]
}
这是我正在使用的代码。
import os
import boto3
import requests
from requests_aws4auth import AWS4Auth
es_host = os.environ['ES_HOST']
es_index = "Metadata"
es_type = "episodes"
url = es_host + '/' + es_index + '/' + es_type + '/'
region = 'us-east-1'
service = 'es'
credentials = boto3.Session().get_credentials()
awsauth = AWS4Auth(credentials.access_key,credentials.secret_key,region,service,session_token=credentials.token)
def lambda_handler(event,context):
print(event)
for record in event['Records']:
id = str(record['dynamodb']['Keys']['uuid']['S'])
if record['eventName'] == 'REMOVE':
res = requests.delete(url + id,auth=awsauth)
else:
document = record['dynamodb']['NewImage']
res = requests.put(url + id,auth=awsauth,json=document,headers={"Content-Type": "application/json"})
我确定这是需要解决的小问题,但如果有人可以提供帮助,我不确定如何取悦。谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)