-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmain.py
41 lines (31 loc) · 935 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# A lambda function to interact with AWS RDS MySQL
import pymysql
import sys
REGION = 'us-east-1'
rds_host = "example.c7hugt6dv8dv.ap-south-1.rds.amazonaws.com"
name = "example"
password = "examplepassword"
db_name = "example"
def save_events(event):
"""
This function fetches content from mysql RDS instance
"""
result = []
conn = pymysql.connect(rds_host, user=name, passwd=password, db=db_name, connect_timeout=5)
with conn.cursor() as cur:
cur.execute("""insert into test (id, name) values( %s, '%s')""" % (event['id'], event['name']))
cur.execute("""select * from test""")
conn.commit()
cur.close()
for row in cur:
result.append(list(row))
print "Data from RDS..."
print result
def main(event, context):
save_events(event)
# event = {
# "id": 777,
# "name": "appychip"
# }
# context = ""
# main(event, context)