我具有由API网关调用的Under lambda函数
import sys
import logging
import pymysql
import json
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)
Bid=pymysql.escape_string("3")
with conn.cursor(pymysql.cursors.DictCursor) as cur:
cur.execute("select exid,exercise_name,image from exercise where bid = 3")
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方法的Integration Request中,我应该在映射模板中添加什么以从用户获取json格式的数据,以及如何在查询中传递该用户值(例如:select exid,exercise_name,image从出价=“用户提供的价值”)。 AM是AWS和后端开发的初学者。预先感谢
答案 0 :(得分:0)
您可以传递查询参数。为此,您必须在集成请求中提及querystringparameter,并在映射Templet中将json / application添加到lambda代码中的map参数。 cur.execute(“ select exid,exercise_name,出价= 3的运动图像”) 将此行替换为
cur.execute("select exid,exercise_name,image from exercise where bid = event['params']['querystring']['parameter_name']")
有关更多信息,请检查此 pass parameter to lambda from api gateway