How to fix Error: Error creating Lambda function: InvalidParameterValueException in Terraform

TerraformINTERMEDIATEMEDIUMUpdated Dec 30, 2025ยท 98 views

The "InvalidParameterValueException" error occurs when creating AWS Lambda functions with Terraform due to invalid configuration parameters. Common causes include S3 bucket region mismatches, VPC permission issues, IAM role problems, or exceeding service quotas.

Quick fix

Fixes Error: Error creating Lambda function: InvalidParameterValueException

resource "aws_lambda_function" "example" {
  filename = "lambda.zip"
  s3_bucket = "my-bucket"  # This bucket must be in same region as function
  s3_key    = "deployments/lambda.zip"

  region = "us-east-1"  # Lambda region
}
  1. Verify S3 bucket region matches Lambda region
  2. Validate Lambda runtime is supported
  3. Check memory size and timeout values
  4. Correct handler format for your runtime
terraform โ€” error
resource "aws_lambda_function" "example" {
filename = "lambda.zip"
s3_bucket = "my-bucket" # This bucket must be in same region as function
s3_key = "deployments/lambda.zip"
region = "us-east-1" # Lambda region
}
Error: Error creating Lambda function: InvalidParameterValueException

What this error means

When Terraform attempts to create a Lambda function via the AWS API, AWS validates all provided parameters. The InvalidParameterValueException error indicates that at least one parameter value fails validation for the CreateFunction operation. Unlike syntax errors in Terraform itself, this error comes from AWS rejecting the configuration during the actual function creation. The root cause requires examining the specific error message alongside your Terraform configuration to identify which parameter AWS deemed invalid.

Typical symptoms

  • terraform apply fails with "InvalidParameterValueException"
  • Error message includes specific parameter name (e.g., MemorySize, Runtime)
  • Creation works in AWS console but fails with Terraform
  • Error occurs immediately when applying Terraform changes
  • Works locally but fails in CI/CD pipeline
  • Specific error about S3 bucket region or network interface permissions
  • Error mentioning quotas or limits exceeded

Common causes

  1. S3 bucket containing Lambda code is in a different region than the Lambda function
  2. IAM execution role missing required permissions for VPC configuration
  3. Memory size outside valid range (128 MB to 10,240 MB, in 1 MB increments)
  4. Runtime version is unsupported or deprecated (e.g., Python 2.7, Node.js 10.x)
  5. Handler format is incorrect for the specified runtime
  6. Timeout exceeds maximum allowed value (900 seconds) or is below 1 second
  7. Environment variables exceed 4 KB size limit
  8. Combined function code and Lambda layers exceed 262 MB size limit
  9. Invalid IAM role ARN or role does not exist
  10. VPC configuration with invalid subnet IDs or security group IDs
  11. Architecture specified is neither x86_64 nor arm64
  12. Attempting to add permissions to $LATEST unpublished version
  13. Provisioned concurrency combined with weighted alias for canary deployment
  14. Function creation happening before IAM role has propagated through AWS

How to fix "Error: Error creating Lambda function: InvalidParameterValueException"

1Verify S3 bucket region matches Lambda region

The S3 bucket containing your Lambda deployment package must be in the same AWS region as the Lambda function.

Check your Terraform configuration:

hcl
resource "aws_lambda_function" "example" {
  filename = "lambda.zip"
  s3_bucket = "my-bucket"  # This bucket must be in same region as function
  s3_key    = "deployments/lambda.zip"

  region = "us-east-1"  # Lambda region
}

Verify the S3 bucket location:

bash
aws s3api get-bucket-location --bucket my-bucket --region us-east-1

If the bucket is in a different region, either:
- Create a new S3 bucket in the Lambda region
- Or upload your deployment package to the existing bucket if it's in the correct region

2Validate Lambda runtime is supported

Ensure the runtime you specified is currently supported by AWS Lambda. Deprecated runtimes like Python 2.7, Python 3.6, Node.js 10.x are no longer available.

Check your Terraform configuration:

hcl
resource "aws_lambda_function" "example" {
  runtime = "python3.12"  # Make sure this is supported
}

Current supported runtimes include:
- Python: 3.9, 3.10, 3.11, 3.12
- Node.js: 18.x, 20.x
- Ruby: 3.2, 3.3
- Java: 11, 17, 21
- Go: 1.x
- .NET: 6, 8

Check AWS Lambda documentation for the latest supported runtimes and deprecation timelines.

3Check memory size and timeout values

Memory and timeout must be within valid AWS Lambda limits:

hcl
resource "aws_lambda_function" "example" {
  memory_size = 256   # Must be 128-10240 MB, in 1 MB increments
  timeout     = 30    # Must be 1-900 seconds
}

If you see errors like "MemorySize value failed to satisfy constraint", adjust the memory allocation. You can also request a quota increase via AWS Console if you need more memory than currently available in your account.

4Correct handler format for your runtime

Handler format must match your runtime. Common formats:

Python:

hcl
handler = "lambda_function.handler"  # file.function_name

Node.js:

hcl
handler = "index.handler"  # file.function_name

Go:

hcl
handler = "main"  # Binary name in ZIP root

Java:

hcl
handler = "com.example.App::handleRequest"  # class::method

Verify the handler file exists in your deployment package and the function is exported correctly.

5Fix IAM role permissions for VPC

If using VPC configuration, the Lambda execution role must have permission to create and manage network interfaces:

hcl
resource "aws_iam_role" "lambda_role" {
  assume_role_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Action = "sts:AssumeRole"
      Effect = "Allow"
      Principal = {
        Service = "lambda.amazonaws.com"
      }
    }]
  })
}

resource "aws_iam_role_policy_attachment" "lambda_vpc_policy" {
  role       = aws_iam_role.lambda_role.name
  policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
}

resource "aws_lambda_function" "example" {
  role             = aws_iam_role.lambda_role.arn
  vpc_config {
    subnet_ids         = [aws_subnet.example.id]
    security_group_ids = [aws_security_group.example.id]
  }
}

Ensure the policy is attached BEFORE creating/updating the Lambda function. Use depends_on if needed.

6Verify environment variables stay under 4 KB

Environment variables must not exceed 4 KB total size:

bash
# Calculate size of your environment variables
echo -n "KEY1=value1KEY2=value2KEY3=value3" | wc -c

If you need to pass large configuration or credentials:

hcl
resource "aws_lambda_function" "example" {
  # Use parameters from AWS Systems Manager instead of env vars
  environment {
    variables = {
      SECRETS_ARN = aws_secretsmanager_secret.example.arn
    }
  }
}

Update your Lambda code to fetch large values from AWS Secrets Manager or Parameter Store at runtime.

7Check Lambda layer and code size limits

The combined size of function code plus all layers cannot exceed 262 MB:

bash
# Check uncompressed size
unzip -l lambda.zip | tail -1

# Check compressed size
ls -lh lambda.zip

If you're hitting the limit:

hcl
resource "aws_lambda_function" "example" {
  # Option 1: Remove unused dependencies
  filename = "lambda-slim.zip"

  # Option 2: Use Lambda layers for common libraries
  layers = [aws_lambda_layer_version.dependencies.arn]
}

In your Terraform apply, use two separate operations if updating both code and layers - apply without layers first, then add layers in a second apply.

8Publish function if adding permissions

If the error mentions $LATEST when adding permissions, set publish = true:

hcl
resource "aws_lambda_function" "example" {
  publish = true  # Creates a versioned function instead of $LATEST only
}

resource "aws_lambda_permission" "example" {
  statement_id  = "AllowAPIGateway"
  action        = "lambda:InvokeFunction"
  function_name = aws_lambda_function.example.function_name
  principal     = "apigateway.amazonaws.com"
}

This ensures you can attach permissions to specific versions.

9Add timing delays for IAM propagation

If creating IAM role and Lambda function in the same Terraform apply, IAM changes may not have propagated yet:

hcl
resource "time_sleep" "wait_for_iam_propagation" {
  create_duration = "10s"

  depends_on = [
    aws_iam_role_policy_attachment.lambda_policy
  ]
}

resource "aws_lambda_function" "example" {
  role = aws_iam_role.lambda_role.arn

  depends_on = [
    time_sleep.wait_for_iam_propagation
  ]
}

This ensures IAM role and policies are fully propagated before Lambda creation attempts.

Advanced notes

When combining Lambda with Provisioned Concurrency and weighted aliases (for canary deployments), AWS temporarily makes the alias weighted, which prevents provisioned concurrency. Wait for the canary to finish before using provisioned concurrency. For sensitive information in error messages, upgrade terraform-provider-aws to a recent version that redacts sensitive values. In CI/CD environments, ensure the build runner can access the S3 bucket in the correct region. If using custom runtimes or container images, verify the image is in the same region as the Lambda function. For multi-region deployments, create separate S3 buckets per region and reference the correct bucket for each region's Lambda function.

Frequently asked questions

What does "Error: Error creating Lambda function: InvalidParameterValueException" mean?
When Terraform attempts to create a Lambda function via the AWS API, AWS validates all provided parameters. The InvalidParameterValueException error indicates that at least one parameter value fails validation for the CreateFunction operation. Unlike syntax errors in Terraform itself, this error comes from AWS rejecting the configuration during the actual function creation.
How do I fix "Error: Error creating Lambda function: InvalidParameterValueException"?
The "InvalidParameterValueException" error occurs when creating AWS Lambda functions with Terraform due to invalid configuration parameters. Common causes include S3 bucket region mismatches, VPC permission issues, IAM role problems, or exceeding service quotas.
What causes "Error: Error creating Lambda function: InvalidParameterValueException"?
S3 bucket containing Lambda code is in a different region than the Lambda function IAM execution role missing required permissions for VPC configuration Memory size outside valid range (128 MB to 10,240 MB, in 1 MB increments)
Is the "Error: Error creating Lambda function: InvalidParameterValueException" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading