How I resolve timout, ssl issue in lambda? Also make auto retry after certain seconds when faced with this issue

|2023-12-04T13:20:57.536+00:00|self.do_handshake()|
|---|---|
|2023-12-04T13:20:57.536+00:00|File /var/lang/lib/python3.10/ssl.py, line 1375, in do_handshake|
|2023-12-04T13:20:57.536+00:00|self._sslobj.do_handshake()|
|2023-12-04T13:20:57.536+00:00|ssl.SSLError: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1007)|
|2023-12-04T13:20:57.536+00:00|The above exception was the direct cause of the following exception:|
|2023-12-04T13:20:57.536+00:00|Traceback (most recent call last):|
|2023-12-04T13:20:57.536+00:00|File /var/task/src/ach/textract_emails_ACH/textractEmails.py, line 381, in lambda_handler|
|2023-12-04T13:20:57.536+00:00|emailDetail.update_one({'_id': ObjectId(_id)}, {|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/collection.py, line 1086, in update_one|
|2023-12-04T13:20:57.536+00:00|self._update_retryable(|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/collection.py, line 881, in _update_retryable|
|2023-12-04T13:20:57.536+00:00|return self.__database.client._retryable_write(|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/mongo_client.py, line 1523, in _retryable_write|
|2023-12-04T13:20:57.536+00:00|return self._retry_with_session(retryable, func, s, bulk)|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/mongo_client.py, line 1421, in _retry_with_session|
|2023-12-04T13:20:57.536+00:00|return self._retry_internal(|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/_csot.py, line 107, in csot_wrapper|
|2023-12-04T13:20:57.536+00:00|return func(self, *args, **kwargs)|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/mongo_client.py, line 1462, in _retry_internal|
|2023-12-04T13:20:57.536+00:00|).run()|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/mongo_client.py, line 2315, in run|
|2023-12-04T13:20:57.536+00:00|return self._read() if self._is_read else self._write()|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/mongo_client.py, line 2415, in _write|
|2023-12-04T13:20:57.536+00:00|with self._client._checkout(self._server, self._session) as conn:|
|2023-12-04T13:20:57.536+00:00|File /var/lang/lib/python3.10/contextlib.py, line 135, in __enter__|
|2023-12-04T13:20:57.536+00:00|return next(self.gen)|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/mongo_client.py, line 1252, in _checkout|
|2023-12-04T13:20:57.536+00:00|with server.checkout(handler=err_handler) as conn:|
|2023-12-04T13:20:57.536+00:00|File /var/lang/lib/python3.10/contextlib.py, line 135, in __enter__|
|2023-12-04T13:20:57.536+00:00|return next(self.gen)|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/pool.py, line 1637, in checkout|
|2023-12-04T13:20:57.536+00:00|conn = self._get_conn(handler=handler)|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/pool.py, line 1756, in _get_conn|
|2023-12-04T13:20:57.536+00:00|conn = self.connect(handler=handler)|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/pool.py, line 1585, in connect|
|2023-12-04T13:20:57.536+00:00|sock = _configured_socket(self.address, self.opts)|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/pool.py, line 1296, in _configured_socket|
|2023-12-04T13:20:57.536+00:00|_raise_connection_failure(address, exc, SSL handshake failed: , timeout_details=details)|
|2023-12-04T13:20:57.536+00:00|File /opt/python/pymongo/pool.py, line 411, in _raise_connection_failure|
|2023-12-04T13:20:57.536+00:00|raise AutoReconnect(msg) from error|
|2023-12-04T13:20:57.536+00:00|pymongo.errors.AutoReconnect: SSL handshake failed: ac-sbejfc4-shard-00-02.wlz8p8p.mongodb.net:27017: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1007) (configured timeouts: connectTimeoutMS: 20000.0ms)|

Hi @Prasanth_R1,

Welcome to the MongoDB Community.

Based on the error stack trace, it seems that the issue is originating because your IP is not being whitelisted in MongoDB Atlas. Therefore, this causes the SSL handshake to fail. Could you please verify it and try again?

Also, you can refer to a similar thread here: Error while connecting my database through Mongodb compass

I hope it helps!

Best regards,
Kushagra