tcurdt
tcurdt

Reputation: 15818

limit unreserved concurrency of a lambda function

I don't find the AWS documentation very clear on this, but it seems like there is no way to limit the unreserved concurrency of an AWS Lambda function. Instead it requires a reserved concurrency, which has to be provisioned and therefor comes at an additional costs.

Is that correct?

And even when I try to add a concurrency configuration it fails to apply it for the "$LATEST" version. Why is that?

resource "aws_lambda_provisioned_concurrency_config" "deliver" {
  function_name                     = aws_lambda_function.deliver.function_name
  qualifier                         = aws_lambda_function.deliver.version
  provisioned_concurrent_executions = 1
}

Upvotes: 3

Views: 1999

Answers (3)

psaxton
psaxton

Reputation: 1843

If your Lambda is being used specifically to process SQS messages, a MaxConcurrency property can be specified on the SQS Event Source properties. This helps to prevent re-queued and DLQ'd messages by limiting the number of in flight messages rather than terminating Lambda instances.

The was added in January 2023 and is documented in the AWS Blogs. Note that this only applies to SQS triggered lambdas and is applied per SQS event source -- Subscribing the lambda to multiple SQS queues will be limited per queue, not function.

Upvotes: 0

T.H.
T.H.

Reputation: 859

I believe Reserved Concurrency will do what you're looking for. You can also use autoscaling to control the level of provisioned concurrency (and perhaps even Reserved Concurrency?) based on utilisation.

But you can't allocate provisioned concurrency on an alias that points to the unpublished version ($LATEST).

Upvotes: 1

Mark B
Mark B

Reputation: 201088

Reserved concurrency doesn't have to be provisioned. If you only set reserved_concurrent_executions on the lambda_function resource, instead of creating a aws_lambda_provisioned_concurrency_config resource, then it will simply limit the amount of concurrency for the function. This will also guarantee that the other functions in your account don't use up your Lambda concurrency account limits in a way that prevent this function from executing.

The reserved_concurrent_executions property controls the concurrency limit feature.

The aws_lambda_provisioned_concurrency_config resource controls the provisioned concurrency feature.

Upvotes: 5

Related Questions