下面是我的python lambda函数
import sys
import logging
import pymysql
import json
import boto3
rds_host="rds.amazonaws.com"
name="name"
password="pass"
db_name="DB"
port = 3306
def save_events(event):
result = []
conn = pymysql.connect(rds_host, user=name, passwd=password, db=db_name,
connect_timeout=30)
with conn.cursor(pymysql.cursors.DictCursor) as cur:
cur.execute("select exid,exercise_name,image from exercise where bid = event['params']['querystring']['Bid']")
result = cur.fetchall()
cur.close()
print ("Data from RDS...")
print (result)
workout = json.dumps(result)
workouts=(workout.replace("\"", "'"))
def lambda_handler(event, context):
save_events(event)
return workouts
我在API网关中创建了get方法,并与上述lambda函数集成在一起,在方法请求中,我将查询字符串指定为“出价”,在集成请求中,我将映射模板添加为“出价”:“ $ input.params( 'bid')”,当我测试提供查询参数为“ Bid = 1”的API时,它会返回以下错误
{"errorMessage": "Extra data: line 1 column 6 (char 5)", "errorType": "JSONDecodeError", "stackTrace": [["/var/lang/lib/python3.6/json/__init__.py", 354, "loads", "return _default_decoder.decode(s)"], ["/var/lang/lib/python3.6/json/decoder.py", 342, "decode", "raise JSONDecodeError(\"Extra data\", s, end)"]]}
我也使用了lambda代理集成,并且在上述错误中也得到了相同的结果。请帮助我被打到这里,谢谢。