I am testing my api gateway to call lambda function. i was successful in the test.
i was then trying to make a connection to postgresql through the same lambda
import json
import psycopg2
db_host = "hostname"
db_port = 5432
db_name ="db name"
db_user ="user"
db_pass ="password"
def connect():
conn = None
try :
conn = psycopg2.connect("dbname={} user={} host={} password={}".format(db_name,db_user,db_host,db_pass))
except :
print("connetion error")
return conn
print("Loading function")
def lambda_handler(event, context):
# paring query from the string
name = event['queryStringParameters']['name']
action = event['queryStringParameters']['action']
print('name = '+name )
print('action = '+action)
# body of the response object
transactionResponse = {}
transactionResponse['name'] = name
transactionResponse['action'] = action
transactionResponse['message'] = 'Lambda called from api_gateway'
# construting Http response
responseObject = {}
responseObject['statusCode'] = 200
responseObject['headers'] {}
responseObject['headers']['Content-Type'] = 'application/json'
responseObject['body'] = json.dumps(transactionResponse)
# return the response object
return responseObject
when i tried to trigger it through the API endpoint i got
Unable to import module 'lambda_function': No module named 'psycopg2'
then i went ahead and build my lambda function by downloading the required package and then uploaded a zip file .
when i try to call try the same to trigger the lambda i am getting
Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'lambda_function'
don't know what lamda_function is .
Could any one suggest me out of this slump ? or provide me a way to connect to RDS through lambda from API gateway trigger