CodexBloom - Programming Q&A Platform

Terraform 1.4.0 scenarios to create AWS Lambda function with 'Invalid Function Name' scenarios despite valid configuration

πŸ‘€ Views: 40 πŸ’¬ Answers: 1 πŸ“… Created: 2025-07-24
terraform aws lambda HCL

I'm working on a project and hit a roadblock. I'm optimizing some code but I'm working with an scenario when trying to deploy an AWS Lambda function using Terraform version 1.4.0. The behavior I'm receiving states `behavior: Invalid function name: Function name must be a string matching the pattern '^[a-zA-Z][a-zA-Z0-9:_-]{0,140}$'`. I have verified my function name, and it appears to conform to AWS's naming conventions. Here's the relevant snippet from my Terraform configuration: ```hcl resource "aws_lambda_function" "my_lambda" { function_name = "my_lambda_function_1" handler = "index.handler" runtime = "nodejs14.x" role = aws_iam_role.lambda_exec.arn source_code_hash = filebase64sha256("lambda_function.zip") filename = "lambda_function.zip" } ``` I also ensured that the IAM role specified in `role` exists and has the appropriate permissions. However, when I run `terraform apply`, it fails at the Lambda creation step with the aforementioned behavior. I've tried changing the function name to other variations like `myLambdaFunction` and `my-lambda-function`, but the result is the same. Additionally, I verified that my AWS CLI is configured correctly and I'm using the correct region. Here’s how my provider is configured: ```hcl provider "aws" { region = "us-west-2" } ``` If anyone has encountered a similar scenario or has insights on what might be going wrong, I would appreciate your guidance. I'm exploring on this and not sure where to look next. I'm working with Hcl in a Docker container on Linux. I appreciate any insights! What's the correct way to implement this?