Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. (venv27)[ec2-user@ip-172-30-0-194 applyreplyPythonTest]$ ls /home/ec2-user/venv27/lib64/python2.7/site-packages/psycopg2
  2. errorcodes.py extensions.py extras.py __init__.py _ipaddress.py _json.py pool.py psycopg1.py _psycopg.so _range.pyc sql.pyc tz.py
  3. errorcodes.pyc extensions.pyc extras.pyc __init__.pyc _ipaddress.pyc _json.pyc pool.pyc psycopg1.pyc _range.py sql.py tests tz.pyc
  4. (venv27)[ec2-user@ip-172-30-0-194 applyreplyPythonTest]$
  5.  
  6. #!/usr/bin/python
  7. from __future__ import print_function
  8. import psycopg2
  9. import sys
  10. import pprint
  11. import json
  12. import urllib
  13. import boto3
  14.  
  15.  
  16. def getdata():
  17.  
  18. conn_string = "host='some address' dbname='DBNAME' user='XXXXXXX' password='XXXXXXX'"
  19. # print the connection string we will use to connect
  20. print("Connecting to databasen ->%s" % (conn_string))
  21.  
  22. # get a connection, if a connect cannot be made an exception will be raised here
  23. print('floob')
  24. conn = psycopg2.connect(conn_string)
  25. print('conn.status', conn.status)
  26. print('conn.server_version', conn.server_version)
  27.  
  28. # conn.cursor will return a cursor object, you can use this cursor to perform queries
  29. cursor = conn.cursor()
  30.  
  31. # execute our Query
  32. cursor.execute("SELECT * FROM cognitouser")
  33.  
  34. # retrieve the records from the database
  35.  
  36. results = []
  37. for row in cursor.fetchall():
  38. print(row)
  39. #results.append(row)
  40.  
  41. # print out the records using pretty print
  42. # note that the NAMES of the columns are not shown, instead just indexes.
  43. # for most people this isn't very useful so we'll show you how to return
  44. # columns as a dictionary (hash) in the next example.
  45. #pprint.pprint(records)
  46.  
  47.  
  48.  
  49.  
  50. def lambda_handler(event, context):
  51. #print("Received event: " + json.dumps(event, indent=2))
  52. getdata()
  53. return json.dumps(event)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement