CodexBloom - Programming Q&A Platform

Terraform 1.4.1: how to to Create AWS Lambda Function with 'InvalidConfiguration' scenarios

πŸ‘€ Views: 76 πŸ’¬ Answers: 1 πŸ“… Created: 2025-08-06
terraform aws-lambda aws hcl

I'm working through a tutorial and I'm trying to configure I'm trying to deploy an AWS Lambda function using Terraform 1.4.1, but I keep working with the 'InvalidConfiguration' behavior during the apply phase... I have set up the function with the required IAM role and policy, but it seems like there's an scenario with the configuration of the Lambda itself. Here’s the relevant part of my Terraform configuration: ```hcl resource "aws_iam_role" "lambda_role" { name = "lambda_execution_role" assume_role_policy = jsonencode({ Version = "2012-10-17" Statement = [ { Action = "sts:AssumeRole" Effect = "Allow" Principal = { Service = "lambda.amazonaws.com" } } ] }) } resource "aws_lambda_function" "my_function" { function_name = "my_lambda_function" role = aws_iam_role.lambda_role.arn handler = "index.handler" runtime = "nodejs14.x" source_code_hash = filebase64sha256("lambda_function.zip") filename = "lambda_function.zip" timeout = 10 } ``` When I run `terraform apply`, I receive the following behavior message: ``` behavior: creating Lambda function: InvalidConfiguration: The configuration is invalid. ``` I've confirmed that the `lambda_function.zip` is a valid deployment package, and the IAM role has the required permissions. I also checked that the `handler` is correctly specified. To troubleshoot, I tried using a simple "Hello World" function but still got the same behavior. Additionally, I validated the zip file structure and ensured that it includes the `index.js` file with the correct export. Has anyone encountered this scenario, and what could be the potential causes? Any help would be appreciated! For reference, this is a production CLI tool. I'm using Hcl latest in this project. Any ideas how to fix this?