title: Not all Python code executing in AWS Lambda function
body: <p>I have a simple lambda function which prints an event and then attempts to insert a row into a database. It runs with <strong><strong>no</strong> error</strong>, but does not execute all of the code.</p>
  <p><code>event</code> gets printed, but the row never gets inserted into the table. Anything, even a print statement I put after <code>connection</code> doesn't get executed. I'm guessing something is wrong with the connection, but as far as I know I have no way of telling what is wrong. Are there more logs somewhere? In CloudWatch I see at the end it says Task timed out after 3.00 seconds</p>
  <pre><code>import boto3
  import psycopg2
  
  s3 = boto3.client('s3')
  
  
  def insert_data(event=None, context=None):
      print(event)
  
      connection = psycopg2.connect(user=&quot;xxxx&quot;, password=&quot;xxxx&quot;,
                                    host=&quot;xxxx&quot;, port=&quot;xx&quot;,
                                    database=&quot;xxxx&quot;)
  
      cursor = connection.cursor()
      postgres_insert_query = &quot;INSERT INTO dronedata (name,lat,long,other) VALUES ('img2','54','43','from lambda')&quot;
      cursor.execute(postgres_insert_query)
      connection.commit()
      count = cursor.rowcount
      print(count, &quot;Record inserted successfully into mobile table&quot;)
  </code></pre>