Say I have few lambdas connected with DynamoDb, and the number of invocations needs to be limited to a hard limit if 500 requests say, after this the lambda shouldn’t get invoked and cost us billing, how can this be done, I tried out API gateway quota in this we need to have the limit on each of the API and api keys.
Need some other way to implement this.
I tried throttling, but that doesn’t completely stop the lambdas from being getting invoked, so this doesn’t solve the problem
2
Answers
I don’t think this can be achieved using AWS limits. You will need to build it – maybe store the counter and check against. However, what are yoy trying to achieve with this architecture? It doesn’t sound right to stop the applications from working after n number of invocations.
I’m not sure on your use-case, so I’m not sure on which solution to recommend. Knowing the reason you’d wanna limit to 500 would help.
You can use a Cloudwatch alarm that alarms at 500 invocations, have the alarm trigger a Lambda function and that function calls
UpdateEventSourceMapping
and disables the connection between the stream and Lambda. This would prevent the Lambda from being invoked again until you enable it.