Guest User

Untitled

a guest
Apr 19th, 2020
5,842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import pymysql
  2.  
  3. # 1. Install pymysql to local directory
  4. # pip install -t $PWD pymysql
  5.  
  6. # 2. (If Using Lambda) Write your code, then zip it all up
  7. # a) Mac/Linux --> zip -r9 ${PWD}/function.zip
  8. # b) Windows --> Via Windows Explorer
  9.  
  10. # Lambda Permissions:
  11. # AWSLambdaVPCAccessExecutionRole
  12.  
  13. #Configuration Values
  14. endpoint = 'yourendpoint.com'
  15. username = 'your username'
  16. password = 'your password'
  17. database_name = 'your database name'
  18.  
  19. #Connection
  20. connection = pymysql.connect(endpoint, user=username,
  21. passwd=password, db=database_name)
  22.  
  23. def lambda_handler(event, context):
  24. cursor = connection.cursor()
  25. cursor.execute('SELECT * from Transactions')
  26.  
  27. rows = cursor.fetchall()
  28.  
  29. for row in rows:
  30. print("{0} {1} {2}".format(row[0], row[1], row[2]))
Advertisement
Add Comment
Please, Sign In to add comment