Lambda attached to API Gateway is called multiple times even when scheduled once.

0

I have created a lambda which changes desired count of ECS services to 0 in non-working hours and updates back to 1 in working hours. There is an API gateway attached to the lambda with endpoint api/v1/resize/{count}. count is 0 or 1 as mentioned above.

To call the API periodically I created two EventBridge rules with different cron schedules based on work timings. Once the lambda is trigger at specific time set by the cron I see multiple invocations happening, every 10 minutes.

I have increased the timeout to 15 minutes. Even after setting retry count to 0 under asynchronous invocations it is triggering every 10 minutes. How can I ensure that it is called only once at the scheduled time.

2 Answers
0

I am suspecting you are not returning a success code from the API, which is causing a retry.

Why are you using API Gateway at all? Why not invoke the Lambda function directly from EventBridge Scheduler?

profile pictureAWS
EXPERT
Uri
answered 9 days ago
profile picture
EXPERT
reviewed a day ago
  • @Uri, I was returning a success response. I am not sure if there's some specific format in which success code needs to be returned. I didn't give much thought to call the Lambda directly because I thought calling the API which in turn will invoke the function should be the same. I managed to work around it by finally calling the Lambda directly.

  • If you are calling the Lambda from API Gateway using Lambda Proxy integration, you should return from the Lambda function something like:

    {
        "statusCode": 200
    } 
    

    In either case, calling Lambda directly is the better approach. No need to introduce another component in the middle.

0

Hello.

Is it possible that you are configuring EventBridge with rate instead of cron?
If cron is configured correctly, it should be possible to run it at a specific time.
https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-cron-expressions.html

Also, EventBridge is sometimes executed multiple times, so this may be related.
https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-troubleshooting.html#eb-rule-triggered-more-than-once

In rare cases, the same rule can run more than once for a single event or scheduled time, or the same target can be invoked more than once for a given triggered rule.

Also, are there any errors when running Lambda?

profile picture
EXPERT
answered 10 days ago
  • It runs at the specified time. But once it runs it keeps on running every 10 minutes. There are no errors as such.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions