Terraform error "Provisioned Concurrency Configs cannot be applied to unpublished function versions" - how to solve?

Viewed 3169

I attempted to create a Provisioned Concurrency Lambda like so:

locals {
  lambda_name = "mylambda"
  provisioned_concurrency = 10
}

module "mylambda-lambda" {
  source = "terraform-aws-modules/lambda/aws"
 
  function_name = "${var.environment_name}-${local.lambda_name}"
  // abriged config detailes
}


module "mylambda-alias" {
  source = "terraform-aws-modules/lambda/aws//modules/alias"
  name = local.lambda_name
  function_name = module.mylambda-lambda.this_lambda_function_name
}

resource "aws_lambda_provisioned_concurrency_config" "auth_authorizer" {
  function_name = module.mylambda-lambda.this_lambda_function_name
  provisioned_concurrent_executions = local.provisioned_concurrency
  qualifier = module.mylambda-alias.this_lambda_alias_name
}

It shows in the console that a qualifier (apparently, the alias) is set to $LATEST.

but with Concurrency setup I got an error

Error: error putting Lambda Provisioned Concurrency Config (<lambda name>): InvalidParameterValueException: Provisioned Concurrency Configs cannot be applied to unpublished function versions.
{
  RespMetadata: {
    StatusCode: 400,
    RequestID: "392f5609-086e-43f6-89af-a0ec0f7e3dc7"
  },
  Message_: "Provisioned Concurrency Configs cannot be applied to unpublished function versions.",
  Type: "User"
}

How this error can be avoided?

1 Answers

As pointed out by @jellycsc, you need to publish a new version.

You are already using the terraform aws module for this, which accepts the flag publish

module "mylambda-lambda" {
  source = "terraform-aws-modules/lambda/aws"
  publish = true
 
  function_name = "${var.environment_name}-${local.lambda_name}"
  // abriged config detailes
}

full example here

Related