Я читаю данные из корзины s3 и вставляю эти данные в aws эластичный поиск с помощью aws lambda.
Если я использую request.post, тогда он работает. Но мне нужен конвейер в качестве параметра.
from elasticsearch import Elasticsearch, RequestsHttpConnection
import boto3
import re
import requests
from requests_aws4auth import AWS4Auth
region = 'us-east-2' # 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)
host = 'https://search-internship6-aqt7s3tuokjcvx7um3lmm7wvbe.us- east-2.es.amazonaws.com/' # the Amazon ES domain, including https://
index = 'lambda-s3-index11'
type1 = 'lambda-type10'
url1 = host + '/' + index + '/' + type1
headers = {"Content-Type": "application/json"}
s3 = boto3.client('s3')
#r=requests.get(url=url1,auth=awsauth)
#print("request ",r)
#es = Elasticsearch([ 'https://search-internship6-aqt7s3tuokjcvx7um3lmm7wvbe.us-east-2.es.amazonaws.com'])
print("Hello1")
es = Elasticsearch(
'https://search-internship6-aqt7s3tuokjcvx7um3lmm7wvbe.us-east-2.es.amazonaws.com',
http_auth = awsauth,
use_ssl = True,
verify_certs = True,
connection_class = RequestsHttpConnection
)
# Lambda execution starts here
def handler(event, context):
#r=requests.get(url= host ,auth=awsauth,headers=headers)
#print("request :",r)
print("es :",es.info())
for record in event['Records']:
# Get the bucket name and key for the new file
bucket = record['s3']['bucket']['name']
key = record['s3']['object']['key']
# Get, read, and split the file into lines
obj = s3.get_object(Bucket=bucket, Key=key)
body = obj['Body'].read()
lines = body.splitlines()
# Match the regular expressions to each line and index the JSON
for line in lines:
# ip = ip_pattern.search(line).group(1)
# timestamp = time_pattern.search(line).group(1)
# message = message_pattern.search(line).group(1)
print(line)
# document = { "ip": ip, "timestamp": timestamp, "message": message }
#r = requests.post(url1, data=line, auth=awsauth, headers=headers)
es.index(index='internship11', doc_type='packets11', body=line, pipeline='epoch-to-format')
print("hello2")
#r = requests.post(url1, data=line, auth=awsauth, headers=headers)
#print(es.info())
Я получаю эту ошибку.
ConnectionError (HTTPSConnectionPool (host = 'https', port = 443): превышено максимальное количество попыток с URL: //search-internship6-aqt7s3tuokjcvx7um3lmm7wvbe.us-east-2.es.amazonaws.com/:443/ (вызвано NewConnectionError (': не удалось установить новое соединение: [Errno -2] имя или служба неизвестна',))), вызвано: ConnectionError (HTTPSConnectionPool (host= 'https', порт = 443): максимальное количество повторных попыток превышено с помощью url: //search-internship6-aqt7s3tuokjcvx7um3lmm7wvbe.us-east-2.es.amazonaws.com/:443/ (вызвано NewConnectionError (': не удалось установитьновое соединение: [Errno -2] Имя или служба не известны ',))): ConnectionError