3

Is there any way to apply an autoscaling configuration to AWS Lambda provisioned concurrency using terraform?

I want to scale it up during peak hours, and ideally maintain an N+1 hot concurrency rate.

I looked here but found no reference to Lambdas: https://www.terraform.io/docs/providers/aws/r/appautoscaling_policy.html

Kloar
  • 1,109
  • 2
  • 9
  • 25
  • terraform works on top of cloudformation (cfn), and there is cfn [example](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-applicationautoscaling-scalabletarget.html#aws-resource-applicationautoscaling-scalabletarget--examples) for lambda. Maybe it could be used to construct corresponding terraform code? – Marcin Jun 05 '20 at 12:21

1 Answers1

1

The feature to control the auto-scaling of lambdas was added Dez.2019 (see this blog). As long as this is not available through Terraform you have a couple of options to work around this

  1. Use a terraform provisioner to set up the provisioning rules through the aws-cli. Instructions which commands to run can be found in the AWS-Docs.
  2. Invoke the lambda yourself from time to time to keep it warm, see e.g. this post or this stackoverflow question
  3. Use a different service that provides more control, like ECS
Falk Tandetzky
  • 5,226
  • 2
  • 15
  • 27
  • I'm not sure this is true. https://aws.amazon.com/blogs/aws/new-provisioned-concurrency-for-lambda-functions/ "Using Application Auto Scaling to automatically scale Provisioned Concurrency With Application Auto Scaling you can automate configuring the required concurrency for your functions. As policies, Target Tracking and Scheduled Scaling are supported. Using these policies, you can automatically increase the amount of concurrency during times of high demand and decrease it when the demand decreases." – Kloar Jun 08 '20 at 08:36
  • Thanks for the hint @Kloar. It seems this is somewhat outdated. This post https://aws.amazon.com/blogs/aws/new-provisioned-concurrency-for-lambda-functions/ sounds like Lambda can now be controlled better. My guess is that this might not have found its way into terraform yet. So the workaround suggested here might still be the best option for the now. – Falk Tandetzky Jun 08 '20 at 09:13
  • I improved the question according to the hint from @Kolar. Thanks for the input! – Falk Tandetzky Jun 08 '20 at 09:34
  • 1
    Thanks! Seems like using a null provisioner with an exec is the way to go! – Kloar Jun 08 '20 at 09:47
  • Made the solution using the provisioner the first option, as this is really what the question asked for. – Falk Tandetzky Jun 08 '20 at 10:19