AWS Lambda Python Function Called Twice

1

Hi,

I have written a small python function which generates unique codes to be used on some logic and returns back. It takes less than a second and is done asynchronously (with 0 tries).

But everytime it executes this function twice when that function url is called. And there seems to be no error and returning 200 code after the code generation. When I saw the log, it says different request Ids for both with just one second difference ?

Any idea how to resolve this ?

Thanks,

-- rishi

PS: I just tested it with the TEST function in the AWS Lambda area and it runs only once and results are as expected. Only when I run the url (function) it runs twice ? Any pointers for that ? Thanks in advance !

Rishi
질문됨 10달 전622회 조회
2개 답변
0
수락된 답변

Hello.
If an asynchronous call is executed twice, the most likely scenario is that an error has occurred.
However, in this case, since the response is 200 and the program is running without error, it is necessary to check that the caller is not executing the program continuously.
https://docs.aws.amazon.com/lambda/latest/dg/invocation-retries.html

Asynchronous invocation – Lambda retries function errors twice. If the function doesn't have enough capacity to handle all incoming requests, events might wait in the queue for hours or days to be sent to the function. You can configure a dead-letter queue on the function to capture events that weren't successfully processed. For more information, see Asynchronous invocation.

The following document contains checkpoints for consecutive runs.
Please check once.
https://repost.aws/knowledge-center/lambda-function-duplicate-invocations

By the way, am I right in thinking that there are no errors left in CloudWathc Logs?

profile picture
전문가
답변함 10달 전
profile pictureAWS
전문가
검토됨 10달 전
  • Thanks for the pointers... but I have checked these and looks like there is no error. Also, I just tested it with the TEST function in the AWS Lambda area and it runs only once and results as expected. Only when I run the url (function) it runs twice ? Any pointers for that ? Thanks in advance !

  • Are there any clients that use function URLs that are executed twice in a row? Is there a mechanism in place to make consecutive requests on the client side?

  • I just wrote this function today and its not used by anything at the moment. I wanted to test it first so, I am calling the (function) URL directly from the browser. Just once and it runs twice, but when I test from the Function-Test (lambda) it runs once and as expected. Very strange !

  • I checked in my environment and two logs were output if the browser is Google Chrome. With Microsoft Edge, only one log was output. So the problem is likely to be in the browser.

  • Here is the log of my attempt. The red boxed area is the log when accessed by Chrome. In the case of Chrome, two logs were output. The blue boxes are logs accessed by Microsoft Edge. In the case of Microsoft Edge, only one log is output.
    So please change your browser and try accessing the site. Perhaps the results will change. edge

0

Jan 2024, The issue with the direct invocation of the lambda function URL still exists. There is a simple workaround although cost wise it will not save much. Just add a query parameter to the function URL: yourfunctionurl?somequery=xxxxx When the function is auto invoked second time the somequery value will be blank / null / None. Use that to return the function.

답변함 4달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠