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
posta 10 mesi fa613 visualizzazioni
2 Risposte
0
Risposta accettata

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
ESPERTO
con risposta 10 mesi fa
profile pictureAWS
ESPERTO
verificato 10 mesi fa
  • 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.

con risposta 4 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande