Skip to content

Instantly share code, notes, and snippets.

@perryism
Created September 13, 2019 21:17
Show Gist options
  • Save perryism/d90758c47e63ab1f4e755fe808251c16 to your computer and use it in GitHub Desktop.
Save perryism/d90758c47e63ab1f4e755fe808251c16 to your computer and use it in GitHub Desktop.
elastic search client using aws credentials
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