Table of Contents
The Error
Error creating Lambda Function: InvalidParameterValueException
What Causes This
Lambda creation fails due to invalid configuration. Common causes: wrong handler format, unsupported runtime, deployment package too large (50MB zipped / 250MB unzipped), IAM role not yet propagated, or VPC configuration issues.
How to Fix It
Solution 1: Fix Handler Format
# Handler format: filename.function_name (without extension)
resource "aws_lambda_function" "api" {
filename = "lambda.zip"
function_name = "my-api"
role = aws_iam_role.lambda.arn
# Python: file_name.function_name
handler = "main.handler" # main.py → def handler(event, context)
# Node.js: file_name.export_name
# handler = "index.handler" # index.js → exports.handler
# Go: bootstrap (for provided.al2023 runtime)
# handler = "bootstrap"
runtime = "python3.12"
}
Solution 2: Wait for IAM Role Propagation
resource "aws_iam_role" "lambda" {
name = "lambda-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = { Service = "lambda.amazonaws.com" }
}]
})
}
# Add a delay for IAM propagation
resource "time_sleep" "wait_for_iam" {
depends_on = [aws_iam_role.lambda]
create_duration = "10s"
}
resource "aws_lambda_function" "api" {
depends_on = [time_sleep.wait_for_iam]
function_name = "my-api"
role = aws_iam_role.lambda.arn
handler = "main.handler"
runtime = "python3.12"
filename = "lambda.zip"
}
Solution 3: Check Package Size
# Check zip size (max 50MB for direct upload)
ls -lh lambda.zip
# If too large, use S3
aws s3 cp lambda.zip s3://my-deployments/lambda.zip
resource "aws_lambda_function" "api" {
s3_bucket = "my-deployments"
s3_key = "lambda.zip"
function_name = "my-api"
role = aws_iam_role.lambda.arn
handler = "main.handler"
runtime = "python3.12"
}
Prevention Tips
- Pin provider versions — avoid surprise breaking changes
- Use CI/CD — catch errors before they hit production
- Test with
terraform plan— always review before applying - Keep Terraform updated — newer versions have better error messages
- Use
terraform validate— catches syntax errors early
Hands-On Courses
Learn to avoid these errors with interactive, project-based courses:
- Terraform for Beginners on CopyPasteLearn
- Terraform By Example — practical code examples
- Terraform Cheat Sheet — quick reference for all commands
Related Articles
- Terraform Troubleshooting - Common Errors and Solutions
- Terraform Enabling and Using Debugging
- Debugging with TFLint
Conclusion
This error is common and fixable. Follow the solutions above, and check our Terraform course for hands-on training that covers real-world troubleshooting scenarios.

