本文介绍了在AWS Lambda服务中从其他Lambda调用Lambda是一个好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个lambda函数,所有这些函数都有一个共同的函数.由于它是通用的,因此大多数代码都在该通用函数中.因此,为该特定功能考虑单独的lambda函数是合乎逻辑的.

I have couple of lambda functions and all of these functions have one function common. Since it is common and most of the code is in that common function. So it is logical to consider separate lambda function for that particular function.

但是当我想到成本预期时,这让我感到沮丧.我的意思是,调用一个lambda会自动调用另一个lambda.因此,一项活动将雇用两种不同的资源.而且看来我并不划算.是吗?

But It discouraged me when i think about cost prospective. I mean, invoking one lambda will automatically invoke another lambda. So one event will hire two different resources. and it does not seems me cost effective. Is it so?

推荐答案

它一直都在做.我已经按计划运行Lambda,这是确定性的,其中要根据各种因素来调用其他Lambda.

It's done all the time. I've had Lambdas running on a schedule be deterministic in which additional Lambdas to invoke based on various factors.

但是,您必须牢记常见的功能"在做什么,以及这不仅会影响成本,而且会影响性​​能.

However, you have to keep in mind what that common "function" is doing and how that impacts not only cost but, performance.

在架构无服务器应用程序或应用程序内的无服务器组件时,有两种主要的心态.您可以将AWS Lambda,Azure Functions,Google Cloud Functions等视为一个功能"解决方案,真正将"micro"置于微服务中.或者,您可以将Lambda用作一组逻辑函数(我仍将其视为应用程序的一个函数..."),在单个Lambda中您可以拥有多个函数.两者都是完全有效的方法,在调试=)时可能会减少麻烦.

There's two main mindsets when you architect your serverless app or the serverless components within an app. You can think of AWS Lambda, Azure Functions, Google Cloud Functions, etc. as a "one function" solution truly putting the "micro" in microservice. Or you can use a Lambda as a logical group of functions (what I would still consider "one function...of your app") where you'd have multiple within a single Lambda. Both are completely valid approaches and one will probably result in less headaches while debugging =)

如果您具有多个Lambda的通用功能,则可能需要在到达另一个Lambda之前考虑在代码中进行处理.我的意思是像软件包或库之类的东西.例如,使用Node.js,您只需使用NPM导入该通用功能,就可以从一个位置进行维护,并根据需要简单地更新依赖它的所有内容.

If you have a common function for several Lambdas you may want to consider handling this in your code before reaching for another Lambda. By that I mean something like packages or libraries. For example with Node.js, you'd just use NPM to import in that common function so you can maintain it from one place and simply update anything relying on it as needed.

尽量不要采用云函数",而是将每个函数拆分为一个新的Lambda.

Try not to take "cloud function" so literally and split every single function into a new Lambda.

请记住,Lambda的费用最低,因为它会四舍五入至最接近的100ms.因此,如果您要调用一些实际上运行速度非常快的通用函数,那么我不会将其分离到新的Lambda中.您将付出更多,但是,您的表现也会受到阻碍.

Keep in mind that there's a minimum charge for Lambda because it rounds up to the nearest 100ms. So if you're calling some common function that actually runs really fast... I wouldn't separate it out into a new Lambda. You're going to pay more but, also your performance will be hindered too.

您的里程会像其他任何事物一样变化.云功能有点给我们一个全新的维度.尽管它们非常方便,但是如果不仔细计划,它们实际上会降低性能并增加成本.

Your mileage will vary like anything else. Cloud functions kinda give us a whole new dimension to think about. While they are super convenient, they can actually degrade performance and increase costs if not carefully planned.

这篇关于在AWS Lambda服务中从其他Lambda调用Lambda是一个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 08:10