For some time I struggled to do this. Currently, the boto3 library does not support the creation of signed es requests, although since I raised the question with them, it has become a function request.
Here is what I did in the meantime using the DavidMuller library mentioned above and boto3 to get my STS session credentials:
import boto3 from aws_requests_auth.aws_auth import AWSRequestsAuth from elasticsearch import Elasticsearch, RequestsHttpConnection session = boto3.session.Session() credentials = session.get_credentials().get_frozen_credentials() es_host = 'search-my-es-domain.eu-west-1.es.amazonaws.com' awsauth = AWSRequestsAuth( aws_access_key=credentials.access_key, aws_secret_access_key=credentials.secret_key, aws_token=credentials.token, aws_host=es_host, aws_region=session.region_name, aws_service='es' )
Hope this saves you a little time.
source share