| 1234567891011121314151617181920212223242526272829303132 |
- import pymysql
- import boto3
- def updata_db(m_key,m_value):
- db = pymysql.connect(
- host='127.0.0.1',
- port=3306,
- user='root',
- passwd='123***123***',
- db='cmd',
- charset='utf8mb4')
- cursor = db.cursor()
- sql = f"INSERT INTO kv(mykey,myvalue) VALUES('{m_key}','{m_value}')"
- try:
- cursor.execute(sql)
- db.commit()
- except Exception as e:
- print('ERROR : '+e)
- db.rollback()
- db.close()
- def lambda_handler(event, context):
- # TODO implement
- sec = event['Records'][0]['messageAttributes']
- m_key = sec['mykey']['stringValue']
- m_value = sec['myvalue']['stringValue']
- print(m_key,m_value)
- updata_db(m_key,m_value)
-
|