I have an AWS Fargate that needs to query Elasticsearch and Dynamodb. The role associated with the cluster has permission to access those services. After a while (about 40 minutes) I start to get this error AuthorizationException: TransportError(403, '{"message":"The security token included in the request is expired"}')
. It's the error raised when I try to access Elasticsearch and if I try to access Dynamodb, I don't get that error.
I'm using boto3 version 1.9.160 and I get the credentials using these lines of codes:
session = boto3.Session()
dynamodb_client_nvirginia = session.client(service_name='dynamodb')
aws_auth = AWS4Auth(
session.get_credentials().access_key, session.get_credentials().secret_key, 'us-east-1', 'es', session_token=session.get_credentials().token)
elasticsearch_client = Elasticsearch(
hosts=[{'host': 'my-elasticsearch-host', 'port': 443}],
http_auth=aws_auth, use_ssl=True, verify_certs=True,
connection_class=RequestsHttpConnection, timeout=30, max_retries=10, retry_on_timeout=True)
I read that the credentials are refreshed automatically by boto3.
As a try, I decided to refresh the credentials to connect to Elasticsearch after 30 minutes but I'm still getting the same error.
What am I doing wrong?