title: Task timed out when connecting documentdb through pymongo in aws lambda
body: <p>I'm trying to fetch my bookings collection from AWS Document db cluster. I've maintained the credentials using AWS Secret Manager and passing them to connect. However, it gives me a Task Timed Out Error of 900 seconds. (I increased the time limit to 15 mins since it gave the same error with  lesser duration)</p>
  <p>The error is as such:</p>
  <blockquote>
  <p>{
  &quot;errorMessage&quot;: &quot;2021-08-19T09:05:22.872Z a96e95cb-4c42-4880-b339-9cb29e83c1ec Task timed out after 900.10 seconds&quot;
  }</p>
  </blockquote>
  <p>Code snippet:</p>
  <pre><code>def lambda_handler(event, context): 
      
      db = create_mongo_connection()
      print(db)
      print(&quot;aaaaa&quot;)                    # this gets printed -- debugging 
      bookings = db.bookings.find({})   # bookings collection not fetched
      print(&quot;bbbbb&quot;)                    # this does not get printed -- debugging 
  
  #configuration settings maintained in environment variables 
  mongoconfig = os.environ['mongoconfig']
  
  def create_mongo_connection():
      try :
          secretsmanager = get_secret()
          SecretString = json.loads(secretsmanager)
          username = SecretString['username']
          password = SecretString['password']
          host = SecretString['host']
          port = SecretString['port']
          mongoclient = MongoClient(host, port, username=username, password=password, 
          authSource='admin',  ssl_ca_certs='rds-combined-ca-bundle.pem',retryWrites='false')
          dbname = mongoconfig['db_name']
          print(dbname)
          return mongoclient[dbname]
      except Exception as e:
          print(&quot;Exception : &quot;, e, &quot;\nTraceback : &quot;, format_exc())
  </code></pre>