箭头函数和lambda函数

    科技2026-08-15  8

    箭头函数和lambda函数

    When you look at the serverless world, you will see a lot of benefits such as reduced labor cost, reduced risk, reduced resource cost, and increased flexibility of scaling. These benefits don’t come free though, we must accept some of the cons too, for example debugging, cold starts, or vendor lock-in, etc…

    当您观察无服务器世界时,您会看到很多好处,例如减少了人工成本,降低了风险,降低了资源成本并增加了扩展的灵活性。 这些好处并不是免费的,我们也必须接受一些弊端,例如调试,冷启动或供应商锁定等。

    We should be aware of this is a new era of infrastructure and it’s slowly maturing. Let’s think about developing a project. When you start coding, I guess that the most important part will be about debugging it. For this reason, we should be feeling free to debug it :) But debugging serverless is very difficult as it is with any distributed application.

    我们应该意识到,这是基础架构的新时代,并且它正在逐渐成熟。 让我们考虑开发一个项目。 当您开始编码时,我想最重要的部分将是调试它。 出于这个原因,我们应该可以自由地调试它:)但是,与任何分布式应用程序一样,无服务器调试非常困难。

    Nevertheless, how hard the thorny problems are, there is a solution for them. I had seen the Thundra on a tweet and it looked like a very cool solution for remote debugging even for the serverless world. Today I will try to demonstrate how you can use it easily. This demonstration will be part of the online debugging side.

    尽管如此,棘手的问题有多难解决,有一个解决方案。 我在推特上看到了Thundra,即使对于无服务器的世界,它看起来也是一个非常不错的远程调试解决方案。 今天,我将尝试演示如何轻松使用它。 该演示将是在线调试方面的一部分。

    Firstly you should register to https://www.thundra.io, afterwards, you will be getting a token for debugging. You can also take the token using the Settings page. It will look as below picture.

    首先,您应该注册到https://www.thundra.io ,之后,您将获得用于调试的令牌。 您也可以使用“设置”页面获取令牌。 它将如下图所示。

    https://console.thundra.io/settings/debugger https://console.thundra.io/settings/debugger

    You have to install a debugger plugin called Debugger for AWS Lambda. I am using IntelliJ but there is one more plugin option for VSCode.

    您必须安装一个称为Debugger for AWS Lambda的调试器插件。 我正在使用IntelliJ,但是VSCode还有一个插件选项。

    Thundra IntelliJ Plugin Thundra IntelliJ插件

    As I mentioned before, you should take a token. This token will be able to ensure connecting to Thundra Broker Host in order to start the debug process remotely. Let’s see it.

    如前所述,您应该持有令牌。 该令牌将能够确保连接到Thundra Broker Host,以便远程启动调试过程。 让我们来看看它。

    Thundra IntelliJ Plugin Configuration Thundra IntelliJ插件配置

    After all these configurations are done, we should get to the AWS Lambda Console. We should add some configurations to the console too.

    完成所有这些配置后,我们应该进入AWS Lambda控制台。 我们也应该向控制台添加一些配置。

    The first one is about custom runtime. The AWS gives us a chance for custom runtime. We can add it as a layer.

    第一个关于自定义运行时。 AWS为我们提供了自定义运行时的机会。 我们可以将其添加为图层。

    arn:aws:lambda:eu-west-2:269863060030:layer:thundra-lambda-java-layer:56 arn:aws:lambda:eu-west-2:269863060030:layer:thundra-lambda-java-layer:56

    The version ARN is supported by Thundra Team. I didn’t deep dive into custom runtime but It maybe adding some environment variables onto custom runtime to open remote debugging or being used JDI over JPDA.

    Thundra Team支持版本ARN。 我没有深入研究自定义运行时,但是可能在自定义运行时中添加了一些环境变量以打开远程调试或在JPDA上使用JDI。

    To use online debugging feature, you need to use Thundra layer version 42 or higher and change runtime to Custom runtime.

    要使用在线调试功能,您需要使用Thundra层版本42或更高版本, 并将运行时更改为Custom runtime 。

    We added custom runtime, now we’re adding token using environment variables on the AWS Lambda Console.

    我们添加了自定义运行时,现在我们在AWS Lambda控制台上使用环境变量添加令牌。

    https://console.thundra.io/settings/debugger https://console.thundra.io/settings/debugger

    The last part of the configuration is about changing the custom runtime. You can change it using the AWS Lambda Console.

    配置的最后一部分是关于更改自定义运行时。 您可以使用AWS Lambda控制台进行更改。

    Finally, you can start debugging on the IntelliJ with the pre-configured plugin and push the button called Test on the AWS Lambda Console.

    最后,您可以使用预配置的插件在IntelliJ上开始调试,然后在AWS Lambda控制台上按下名为Test的按钮。

    IntelliJ (I’ve shown it before, please look up.) IntelliJ(我已经显示过了,请向上看。)

    Debugging view.

    调试视图。

    Debugging View 调试视图

    Troubleshooting

    故障排除

    1.Performance

    1.性能

    When you face performance issues, you can follow the below information. You should select the region that is close to your application that will improve your performance.

    遇到性能问题时,可以遵循以下信息。 您应该选择靠近应用程序的区域,以提高性能。

    Thundra provides a broker host on Oregon by default. Moreover, we support different broker hosts listed below. You can select and set to thundra_agent_lambda_debugger_broker_hostenvironment variable to reduce latency during debugging session.

    Thundra默认情况下在俄勒冈州提供经纪人托管。 此外,我们支持下面列出的其他经纪人主机。 您可以选择并设置为thundra_agent_lambda_debugger_broker_host环境变量以减少调试会话期间的延迟。

    debug.thundra.io (us-west-2 — Oregon)

    debug.thundra.io (us-west-2-俄勒冈州)

    debug-us-east-1.thundra.io (us-east-1 — N. Virginia)

    debug-us-east-1.thundra.io (us-east-1-北弗吉尼亚)

    debug-eu-west-2.thundra.io (eu-west-2 — London)

    debug-eu-west-2.thundra.io (eu-west-2-伦敦)

    debug-ap-northeast-1.thundra.io (ap-northeast-1 — Tokyo)

    debug-ap-northeast-1.thundra.io (ap-northeast-1-东京)

    2. The debugging process immediately disconnects

    2.调试过程立即断开

    The latency can cause this problem. So you should increase the timeout value of your lambda function. You can do it over the AWS Lambda Console.

    延迟可能会导致此问题。 因此,您应该增加lambda函数的超时值。 您可以通过AWS Lambda控制台执行此操作。

    Source Codes

    源代码

    Some useful documentation;

    一些有用的文档;

    翻译自: https://medium.com/@gokalp/how-to-remote-debug-lambda-functions-using-thundra-e8d5e780b268

    箭头函数和lambda函数

    Processed: 0.008, SQL: 9