lambda调用函数_从另一个Lambda函数调用AWS Lambda函数

本文详细介绍了如何在AWS环境中创建和调用Lambda函数。通过一个零售商应用示例,展示了如何从ParentFunction调用ChildFunction,进行业务处理并返回结果。涉及创建Lambda函数、设置权限策略、编写Python代码以及测试流程。
摘要由CSDN通过智能技术生成

lambda调用函数

In this article, I am going to explain how to create an AWS Lambda function and then call this function from another Lambda function within the same region. This is a useful scenario in which we may need to execute a second lambda function based on the outcome of some previous logic. Another scenario may be to execute a second lambda function several times by using different parameters.

在本文中,我将解释如何创建一个AWS Lambda函数,然后从同一区域内的另一个Lambda函数调用此函数。 这是一个有用的场景,其中我们可能需要根据某些先前逻辑的结果执​​行第二个lambda函数。 另一种情况可能是使用不同的参数多次执行第二个lambda函数。

For the sake of this article, we will consider a typical retailer application, in which we can purchase different products from a retailer site using a lambda function.

为了本文的目的,我们将考虑一个典型的零售商应用程序,在该应用程序中,我们可以使用lambda函数从零售商站点购买不同的产品。

Architecture Diagram

If you consider the above architecture diagram, you can see that we have an AWS lambda function – the ParentFunction, which assumes a specific role from the IAM (Invoke Other Lambda Function) and then calls another lambda function – the ChildFunction with a payload. Once the execution of the ChildFunction is completed, it returns a response, which is then passed on to the ParentFunction. The ParentFunction receives the response and handles the job accordingly.

如果考虑以上架构图,您会看到我们有一个AWS lambda函数– ParentFunction ,它从IAM( 调用其他Lambda函数 )承担特定角色,然后调用另一个lambda函数–带有有效负载的ChildFunction 。 一旦ChildFunction的执行完成,它将返回一个响应,然后将其传递给ParentFunctionParentFunction接收响应并相应地处理作业。

As in this example, let us assume that the ParentFunction is going to call the ChildFunction with a payload of ProductName, Quantity, and the UnitPrice of that product. The ChildFunction, in turn, will process this payload, calculate the total sales amount, generate a transaction reference ID, and return this information to the ParentFunction.

在此示例中,让我们假设ParentFunction将使用该产品的ProductName,Quantity和UnitPrice的有效负载来调用ChildFunction 。 反过来, ChildFunction将处理此有效负载,计算总销售额,生成交易参考ID,并将此信息返回给ParentFunction

创建第一个AWS Lambda函数– ChildFunction (Creating the first AWS Lambda Function – ChildFunction)

Let us first go ahead and create the ChildFunction, which will process the input payload and return the results to the ParentFunction.

让我们首先继续创建ChildFunction,该函数将处理输入的有效负载并将结果返回给ParentFunction。

Head over to https://console.aws.amazon.com/ and login with your credentials. Once you are inside the console, start searching for “Lambda” and click on the first result that appears from the drop-down.

转到https://console.aws.amazon.com/并使用您的凭据登录。 进入控制台后,开始搜索“ Lambda ”,然后单击下拉菜单中显示的第一个结果。

Search AWS Lambda Function

This will take you to the Lambda Function homepage, where you can create a new lambda function by hitting the “Create Function” button.

这将带您到Lambda函数主页,您可以在其中单击“ 创建函数 ”按钮来创建新的lambda函数。

Create AWS Lambda Function

Let the name of this function be – “C

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值