Skip to content

Commit cde6fb6

Browse files
committed
apparently the auth needs credentials to be generated
1 parent 0aa8429 commit cde6fb6

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

slow_tasks.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@
1010
from constants import AWS_REGION, OPENSEARCH_HOST
1111
from celery_app import celery_app
1212

13-
service = 'es'
14-
credentials = boto3.Session().get_credentials()
15-
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, AWS_REGION, service, session_token=credentials.token)
1613

14+
def get_opensearch_client():
15+
service = 'es'
16+
credentials = boto3.Session().get_credentials()
17+
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, AWS_REGION, service, session_token=credentials.token)
18+
opensearch_client = OpenSearch(
19+
hosts = [{'host': OPENSEARCH_HOST, 'port': 443}],
20+
http_auth = awsauth,
21+
use_ssl = True,
22+
verify_certs = True,
23+
connection_class = RequestsHttpConnection
24+
)
25+
return opensearch_client
1726

1827

1928
device = "cuda" if torch.cuda.is_available() else "cpu"
@@ -46,13 +55,7 @@ def process_audio_stream(
4655
print(f'from realtime: {transcription_from_realtime}')
4756
print(f'whisper large: {transcription}')
4857

49-
search = OpenSearch(
50-
hosts = [{'host': OPENSEARCH_HOST, 'port': 443}],
51-
http_auth = awsauth,
52-
use_ssl = True,
53-
verify_certs = True,
54-
connection_class = RequestsHttpConnection
55-
)
58+
search = get_opensearch_client()
5659

5760
document = {
5861
'timestamp': datetime.utcfromtimestamp(timestamp).isoformat(),

0 commit comments

Comments
 (0)