in source/consumer/lambda_handler.py [0:0]
def connect_es(endpoint):
# Handle aws auth for es
session = boto3.Session()
credentials = session.get_credentials()
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, session.region_name, 'es',
session_token=credentials.token)
print('Connecting to the ES Endpoint: {endpoint}'.format(endpoint=endpoint))
try:
es_client = Elasticsearch(
hosts=[{'host': endpoint, 'port': 443}],
use_ssl=True,
verify_certs=True,
http_auth=awsauth,
connection_class=RequestsHttpConnection)
except Exception as e:
print("Unable to connect to {endpoint}:".format(endpoint=endpoint), e)
else:
print('Connected to elasticsearch')
return es_client