If I wanted to launch a lambda function every 2 minutes, that makes a call to an api with an index number. How would I store the index number for lambda to read upon initialisation and increment it by one every time the lambda function makes a successful api call?
I think that having a dynamo table just for a counter is overkill.
I would argue that using something else other than dynamoDB would be overkill.
DynamoDB is made for this exact purpose. And it is virtually free for your use case. And will only add around more or less 10ms to your run time. Very negligible compared to the cold starts your Lambda will be getting.
If you really want to trim both your DynamoDB cost and your Lambda runtime, you can cache the counter inside the Lambda container (outside your handler).
Assuming, there are no concurrent invocations (triggered via scheduled events only), I would do something like this for each invocation:
counter == 0, read value from DynamoDB. If counter > 0, use that value.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With