Reputation: 1200
I have a simple lambda function which prints an event and then attempts to insert a row into a database. It runs with no error, but does not execute all of the code.
event
gets printed, but the row never gets inserted into the table. Anything, even a print statement I put after connection
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
import boto3
import psycopg2
s3 = boto3.client('s3')
def insert_data(event=None, context=None):
print(event)
connection = psycopg2.connect(user="xxxx", password="xxxx",
host="xxxx", port="xx",
database="xxxx")
cursor = connection.cursor()
postgres_insert_query = "INSERT INTO dronedata (name,lat,long,other) VALUES ('img2','54','43','from lambda')"
cursor.execute(postgres_insert_query)
connection.commit()
count = cursor.rowcount
print(count, "Record inserted successfully into mobile table")
Upvotes: 2
Views: 853
Reputation: 125
hence psycopg2
is an external lib, please upload that lib along with your code into your Lambda Function. So Issue is, it is not able to connect, that's why you are facing a timeout issue.
Upvotes: 0
Reputation: 269826
The typical security setup is:
Lambda-SG
) that permits all outbound access (no need for inbound rules)DB-SG
) that permits inbound access on the appropriate port from Lambda-SG
That is, DB-SG
should specifically reference Lambda-SG
in its inbound rules.
Upvotes: 3