I would like to schedule a lambda function to regularly increment some attributes in a dynamo table, but lambda's concurrency is throwing off the increments by running it multiple times.
Trying to limit concurrency to 1 does not seem to work either, as it often results in a function becoming rate limited before it can complete.
Is there a proper way to setup an aws-lambda function so that it either a) only runs once or b) increments idempotently so that the function could only increment the value once even if it runs concurrently?
Thanks.
It is not clear from your question what triggers your lambda function. If you use a CloudWatch rule to trigger the function on a scheduled basis, only a single invocation will take place for each ‘tick’ which is defined as the rate that you configured.
Regarding your question about idempotency:
If your trigger is synchronous, the lambda will be invoked several times with the same input only in the case of a retry due to a failure and the invocations will not run concurrently. If it is asynchronous, it may be triggered several times and you should write your code to handle this case correctly (though it happens only in a very small portion of the invocations).
It seems that your lambda is triggered more than expected and that may be the problem, not idempotency. In any case, you can use the lambda’s input and the request id of the context to make the code idempotent.