Created
September 13, 2019 21:17
-
-
Save perryism/d90758c47e63ab1f4e755fe808251c16 to your computer and use it in GitHub Desktop.
elastic search client using aws credentials
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
from requests_aws4auth import AWS4Auth | |
from elasticsearch import Elasticsearch, RequestsHttpConnection | |
class AwsElasticSearchClient(Elasticsearch): | |
def __init__(self, **args): | |
session = boto3.Session() | |
creds = session.get_credentials().get_frozen_credentials() | |
awsauth = AWS4Auth( | |
creds.access_key, creds.secret_key, args["region"], "es", session_token=creds.token | |
) | |
args = { | |
"hosts": args["hosts"], | |
"http_auth": awsauth, | |
"use_ssl": True, | |
"verify_certs": True, | |
"connection_class": RequestsHttpConnection | |
} | |
super().__init__(**args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment