How to fix filename conflicts with image_uri in Terraform
The aws_lambda_function resource requires mutually exclusive code deployment options. You cannot use both filename and image_uri in the same Lambda function—choose one based on whether you're deploying from a local file, S3, or container image.
Quick fix
Fixes filename conflicts with image_uri
resource "aws_lambda_function" "example" {
function_name = "my-function"
filename = "lambda.zip" # DELETE THIS
image_uri = "123456...latest" # or DELETE THIS
role = aws_iam_role.lambda.arn
}- Identify which deployment method you need
- Remove conflicting parameters from your resource
- Validate your configuration
- Update required fields based on deployment method
resource "aws_lambda_function" "example" {function_name = "my-function"filename = "lambda.zip" # DELETE THISimage_uri = "123456...latest" # or DELETE THISrole = aws_iam_role.lambda.arn}filename conflicts with image_uri
What this error means
Terraform's aws_lambda_function resource supports multiple ways to specify your Lambda function's deployment package, but these options are mutually exclusive. The filename parameter (for local zip files) conflicts with image_uri (for ECR container images), as well as with s3_bucket and s3_key parameters (for S3-hosted packages). Terraform validates that only one deployment method is specified per function resource. This error means you've accidentally configured more than one of these conflicting parameters, which is invalid in Terraform's provider schema.
Typical symptoms
- Terraform plan or apply fails immediately with conflicting arguments error
- Error message specifically mentions 'filename' conflicts with 'image_uri'
- The error appears when you have both parameters defined in your aws_lambda_function block
- Module or configuration that tries to conditionally set deployment methods fails validation
Common causes
- Both filename and image_uri are specified in the same aws_lambda_function resource block
- Using ternary operators or conditionals that don't properly evaluate to null for unused parameters (Terraform still sees the attribute as configured)
- Copy-pasting example code and forgetting to remove unused deployment parameters
- Reusable Terraform modules that try to support multiple deployment types within a single resource block instead of using separate resources
- Misconfigured variables that provide values for multiple conflicting parameters
How to fix "filename conflicts with image_uri"
Choose one of the three valid deployment methods for your Lambda function:
1. Zip file from local path: Use filename parameter
- Best for: Simple functions, quick local testing
- Example: filename = "lambda.zip"
2. Container image from ECR: Use image_uri parameter
- Best for: Complex dependencies, Docker-based deployments
- Example: image_uri = "123456789.dkr.ecr.us-east-1.amazonaws.com/my-function:latest"
- Requires: package_type = "Image"
3. Zip file from S3: Use s3_bucket, s3_key, and optionally s3_object_version
- Best for: CI/CD pipelines, shared artifact storage
- Example: s3_bucket = "my-bucket" s3_key = "lambda.zip"
Decide which one matches your deployment workflow.
Delete all parameters except the one you chose. Search your aws_lambda_function resource for:
- filename
- image_uri
- s3_bucket
- s3_key
- s3_object_version
Keep only the deployment method you selected in step 1, and delete the others:
Bad (conflicting):
resource "aws_lambda_function" "example" {
function_name = "my-function"
filename = "lambda.zip" # DELETE THIS
image_uri = "123456...latest" # or DELETE THIS
role = aws_iam_role.lambda.arn
}Good (using filename):
resource "aws_lambda_function" "example" {
function_name = "my-function"
filename = "lambda.zip"
role = aws_iam_role.lambda.arn
}Good (using image_uri):
resource "aws_lambda_function" "example" {
function_name = "my-function"
image_uri = "123456789.dkr.ecr.us-east-1.amazonaws.com/my-function:latest"
package_type = "Image"
role = aws_iam_role.lambda.arn
}Run Terraform validate to check for any remaining issues:
terraform validateIf there are no errors, move to the next step. If you still see conflicting arguments errors, ensure you removed all instances of the conflicting parameters.
Depending on your chosen method, add the required companion parameters:
For filename (Zip):
resource "aws_lambda_function" "example" {
function_name = "my-function"
filename = "lambda.zip"
handler = "index.handler" # Required for Zip
runtime = "nodejs18.x" # Required for Zip
role = aws_iam_role.lambda.arn
}For image_uri (Container):
resource "aws_lambda_function" "example" {
function_name = "my-function"
image_uri = "123456789.dkr.ecr.us-east-1.amazonaws.com/my-function:latest"
package_type = "Image" # REQUIRED for image_uri
role = aws_iam_role.lambda.arn
}For S3 (Zip):
resource "aws_lambda_function" "example" {
function_name = "my-function"
s3_bucket = "my-artifact-bucket"
s3_key = "lambda.zip"
handler = "index.handler" # Required for Zip
runtime = "nodejs18.x" # Required for Zip
role = aws_iam_role.lambda.arn
}Now that you've selected a single deployment method, test and apply your changes:
terraform plan
terraform applyThe error should no longer appear. If you still see it, double-check that you removed all conflicting parameters from your resource.
Advanced notes
For reusable modules supporting multiple deployment methods:
If you're building a Terraform module that needs to support both container images and zip files, you cannot use a single aws_lambda_function resource with conditional parameters. Instead, use separate resources with count or for_each:
# Module variables
variable "deployment_type" {
type = string
validation {
condition = contains(["zip", "image"], var.deployment_type)
}
}
# Zip-based Lambda
resource "aws_lambda_function" "zip" {
count = var.deployment_type == "zip" ? 1 : 0
function_name = var.function_name
filename = var.filename
handler = var.handler
runtime = var.runtime
role = aws_iam_role.lambda.arn
}
# Container-based Lambda
resource "aws_lambda_function" "image" {
count = var.deployment_type == "image" ? 1 : 0
function_name = var.function_name
image_uri = var.image_uri
package_type = "Image"
role = aws_iam_role.lambda.arn
}This pattern separates the conflicting configurations into distinct resource blocks, avoiding the validation error entirely.
Managing image updates with Terraform:
When deploying container images via Terraform, you may want Lambda to auto-update when the image is pushed to ECR. To avoid drift detection issues, consider using lifecycle rules or the ignore_source_code_hash equivalent for images, though these require careful state management.
Frequently asked questions
- What does "filename conflicts with image_uri" mean?
- Terraform's aws_lambda_function resource supports multiple ways to specify your Lambda function's deployment package, but these options are mutually exclusive. The filename parameter (for local zip files) conflicts with image_uri (for ECR container images), as well as with s3_bucket and s3_key parameters (for S3-hosted packages). Terraform validates that only one deployment method is specified per function resource.
- How do I fix "filename conflicts with image_uri"?
- The aws_lambda_function resource requires mutually exclusive code deployment options. You cannot use both filename and image_uri in the same Lambda function—choose one based on whether you're deploying from a local file, S3, or container image.
- What causes "filename conflicts with image_uri"?
- Both filename and image_uri are specified in the same aws_lambda_function resource block Using ternary operators or conditionals that don't properly evaluate to null for unused parameters (Terraform still sees the attribute as configured) Copy-pasting example code and forgetting to remove unused deployment parameters
- Is the "filename conflicts with image_uri" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Terraform Official Documentation
- 📖AWS Lambda Function resource documentation(Official Docs)
- 🐙
- 🐙
- 📖AWS Lambda: Container images documentation(Official Docs)