Rainer Plumer
Rainer Plumer

Reputation: 3753

Guarantee limiting AWS Lambda functions to specified budget

I'm new to AWS Lambda (and AWS in general). I need to write some development code for AWS.

Since Lambda functions are billed by execution time and number of requests, I'd like to guarantee that no out-of-control function or route spam would skyrocket costs out of my budget and put me in debt. (It is development code, so I expect there to be mistakes and I don't want them to be expensive ones.)

I know AWS has budget alarms which send you emails, but this is not good enough for me, since it might take days/weeks until I notice a message somewhere.

Is there a way to tell AWS to shut down a service if it is exceeding a budget? I'm looking for something similar to what DigitalOcean does, where you can set a fixed budget.

Upvotes: 1

Views: 425

Answers (2)

ene_salinas
ene_salinas

Reputation: 705

Create a lambda, where its purpose it will be delete lambda's source code deployed (s3 bucket).

Then:

  1. Create billing alarm
  2. Define your metrics Ex: <= 5USD
  3. Create sns topic
  4. Subscribe where endpoint must be lambda function

Some like:

enter image description here

Upvotes: 4

thomasmichaelwallace
thomasmichaelwallace

Reputation: 8474

There's nothing built-in that allows you to simply declare a budget and stop when you hit it (across any of AWS' services.).

You do have a few 'DIY' options though:

  • Limit concurrency and always provide a sensible timeout - if you're not expecting to have more than 5 simultaneous calls to your lambda, or it's not supposed to take more than 10 seconds to finish, then put those restrictions in. That'll limit your exposure to the cost of max concurrency over time to notice. (docs)
  • Use Cloudwatch metrics and alarms. These are much more reactive (to the nearest minute) than budgets. You can set an alarm of sum duration / invocations so that you get notified when you've passed more than X lambda minutes a day (or other). (docs)

Upvotes: 2

Related Questions