Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. from __future__ import print_function
  2.  
  3. import json
  4. import traceback
  5. import psycopg2
  6.  
  7. DB_CLOUD_HOST = '...'
  8. DB_CLOUD_PORT = '...'
  9. DB_CLOUD_USER = '...'
  10. DB_CLOUD_NAME = '...'
  11. DB_CLOUD_PASSWORD = '...'
  12.  
  13.  
  14. def lambda_handler(event, context):
  15. """
  16.  
  17. To test:
  18. echo -n '{"Records": [{"EventVersion": "1.0", "EventSource": "aws:sns", "EventSubscriptionArn": "arn:aws:sns:EXAMPLE", "Sns": {"MessageId": "95df01b5-ee98-5cb9-9903-4c211d41eb6e", "Signature": "EXAMPLE", "Type": "Notification", "TopicArn": "arn:aws:sns:EXAMPLE", "MessageAttributes": {"Test": {"Type": "String", "Value": "TestString"}, "TestBinary": {"Type": "Binary", "Value": "TestBinary"}}, "SignatureVersion": "1", "Timestamp": "1970-01-01T00:00:00.000Z", "SigningCertUrl": "EXAMPLE", "Message": "{...}", "UnsubscribeUrl": "EXAMPLE", "Subject": "TestInvoke"}}]}' | apex invoke update_db --env prod --profile prod
  19.  
  20. """
  21.  
  22. try:
  23. message = json.loads(event['Records'][0]['Sns']['Message'])
  24.  
  25. conn = psycopg2.connect(host=DB_CLOUD_HOST,
  26. port=DB_CLOUD_PORT,
  27. user=DB_CLOUD_USER,
  28. dbname=DB_CLOUD_NAME,
  29. password=DB_CLOUD_PASSWORD)
  30. cur = conn.cursor()
  31. cur.execute("UPDATE ... WHERE ...")
  32.  
  33. conn.commit()
  34. cur.close()
  35. conn.close()
  36.  
  37. except Exception, e:
  38. print('Exception !!!')
  39. print(traceback.format_exc())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement