简体   繁体   English

如何从API网关链接两个Lambda函数

[英]How to link two lambda functions from API gateway

I have two lambda functions 我有两个Lambda函数

Lambda 1: Lambda 1:

def save_events(event):
result = []
conn = pymysql.connect(rds_host, user=name, passwd=password, 
db=db_name,connect_timeout=30)
with conn.cursor() as cur:
cur.execute("SELECT * FROM bodyparts")
for row in cur:
result.append(list(row))
cur.close()
bodyparts = json.dumps(result)
bodyParts=(bodyparts.replace("\"", "'"))
def lambda_handler(event, context):
save_events(event)
return bodyParts

Lambda 2: Lambda 2:

def save_events(event):
result = []
conn = pymysql.connect(rds_host, user=, passwd=, db=, connect_timeout=30)
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

After the successful execution of lambda 1 it will return list as a json object to the browser using API gateway and now how to invoke the lambda 2 function in API gateway based on the user selection from the output of lambda1 function. 成功执行lambda 1之后,它将使用API​​网关将list作为json对象返回给浏览器,现在将根据用户从lambda1函数输出中的选择,如何在API网关中调用lambda 2函数。 In lambda2 how to pass user selected item as "bid" value in query. 在lambda2中,如何在查询中将用户选择的项目作为“出价”值传递。 I know the theory part, really stuck with the implementation part as am a beginner to backend development, Any help would be much appreciated 我知道理论部分,作为后端开发的初学者,真的很喜欢实现部分,任何帮助将不胜感激

I think that a good option for you is AWS Step Function. 我认为AWS Step Function对您来说是一个不错的选择。 If you use Step Functions you can have 2 states with a lambda in each state, the state 1 execute your lambda 1 and pass the result to the second state and execute in it lambda 2. Remember that Step Functions can be called from API Gateway so if you are using API Gateway like endpoint you only need to change the target to Step Functions instead the lambda function. 如果您使用步骤函数,则可以有2个状态,每个状态都具有lambda,状态1执行您的lambda 1,并将结果传递给第二个状态,并在其中执行lambda2。请记住,可以从API Gateway调用Step Functions,因此如果您使用的是API网关(如端点),则只需将目标更改为“阶梯函数”,而不是lambda函数。 A good way to create all this resources is SAM (Serverless Application Model), using swagger. 创建所有这些资源的一个好方法是使用swagger的SAM(无服务器应用程序模型)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 允许从API网关调用所有Lambda函数的权限 - Permission to invoke all Lambda functions from API Gateway 如何从 API Gateway 异步调用 Lambda? - How to invoke Lambda asyncronously from API Gateway? 部署 lambda 函数时如何从无服务器获取 API 网关 ID 作为输出部分 - How to get API Gateway ID as output section from the serverless when lambda functions are deployed 如何将请求的标头块从 API 网关传递到 Step 函数 / lambda? - How to pass to header block of request from API Gateway to Step functions / lambda? 如何处理来自 API 网关的 lambda 错误 - how to handle lambda error from the API gateway 如何使用 VPC 链接和 VPC 端点从私有子网内的 Lambda 响应 API 网关 Web 套接字 - How to respond from a Lambda inside Private Subnet to a API Gateway Web Socket, using VPC Link and VPC Endpoint AWS API Gateway如何监听2个Lambda函数? - How can aws api gateway listen to 2 lambda functions? 如何为两个 api-gateway 创建调用相同的 lambda function - How to create invoke same lambda function for the two api-gateway 只允许 Lambda 函数调用 API 网关 - Only allow Lambda functions to call API Gateway aws api网关和lambda函数超时问题 - Aws api gateway and lambda functions timeout problem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM