Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import json
- import traceback
- import psycopg2
- DB_CLOUD_HOST = '...'
- DB_CLOUD_PORT = '...'
- DB_CLOUD_USER = '...'
- DB_CLOUD_NAME = '...'
- DB_CLOUD_PASSWORD = '...'
- def lambda_handler(event, context):
- """
- To test:
- 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
- """
- try:
- message = json.loads(event['Records'][0]['Sns']['Message'])
- conn = psycopg2.connect(host=DB_CLOUD_HOST,
- port=DB_CLOUD_PORT,
- user=DB_CLOUD_USER,
- dbname=DB_CLOUD_NAME,
- password=DB_CLOUD_PASSWORD)
- cur = conn.cursor()
- cur.execute("UPDATE ... WHERE ...")
- conn.commit()
- cur.close()
- conn.close()
- except Exception, e:
- print('Exception !!!')
- print(traceback.format_exc())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement