多次调用 AWS Lambda Java 函数 [英] AWS Lambda Java function invoked multiple times

查看:24
本文介绍了多次调用 AWS Lambda Java 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 Java 编写的 AWS Lambda 函数(好吧,它实际上是用 Clojure 编写的)并且每次运行它似乎都会被调用 3 次.

I've got an AWS Lambda function I've written in Java (well, it's actually written in Clojure) and it appears to get invoked 3 times every time I run it.

我的函数在超时(设置为最多 5 分钟)内成功运行.它返回一个字符串,当我在控制台中测试该函数时,我可以看到该字符串.

My function runs successfully and well within the timeout (which is set to the max of 5 minutes). It returns a string which I can see output when I test the function in the console.

我在网上看到了一些关于必须调用一些 Context success/done 函数的内容,但在 Java SDK 中看不到(似乎仅适用于 Node?).

I've seen some stuff online about having to call some Context success / done function but can't see that in the Java SDK (seems to be for Node only?).

我错过了什么吗?

当我在控制台中单击测试时不会发生这种情况(它只运行一次),但在通过 CloudWatch 触发器触发或通过 AWS 开发工具包运行时会发生.

This does not occur when I click test in the console (it only runs once) but does happen when triggered via a CloudWatch Trigger or running via the AWS SDK.

谢谢,

多诺万

更新:抱歉,通过触发器运行时不会发生这种情况,仅通过 SDK 和 CLI 运行,所以我正在调用的可能存在一些超时.

Update: apologies, this does not happen when running via the trigger, only via the SDK and CLI, so perhaps there is some timeout in the call I am making.

推荐答案

为了供其他人将来参考,问题是 SDK 和 CLI 达到一分钟的读取超时,然后重试请求.我手动将其设置为 5 分钟以匹配我的 AWS Lambda 超时.

For future reference for anyone else, the issue was the SDK and CLI hitting the read timeout of one minute and then retrying the request. I manually set this to 5 minutes to match my AWS Lambda timeout.

这可以在 CLI 中通过添加 --cli-read-timeout int 来完成,其中 int 是你想要的超时时间(或者简单的 --cli-读取超时 0 完全禁用超时).

This can be done in the CLI by adding --cli-read-timeout int where int is your desired timeout (or simply --cli-read-timeout 0 which disables the timeout altogether).

在 Java SDK 中,可以通过在 ClientConfiguration 对象上调用 setSocketTimeout(int socketTimeout) 来实现

In the Java SDK it can be done by calling setSocketTimeout(int socketTimeout) on the ClientConfiguration object

在使用 Amazonica 的 Clojure 中,将 :client-config {:socket-timeout xxx} 添加到您的凭据映射中.

In Clojure using Amazonica, add :client-config {:socket-timeout xxx} to your credentials map.

这篇关于多次调用 AWS Lambda Java 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆