Terraform 1.4.3: implementing AWS Lambda Function Versioning and Permissions
I'm refactoring my project and I'm learning this framework and I'm integrating two systems and Hey everyone, I'm running into an issue that's driving me crazy. I'm currently working with a scenario with versioning my AWS Lambda functions using Terraform. I have a setup where I'm trying to create a new Lambda function and then publish a version of that function. I want to ensure that the published version has the correct permissions to be invoked by an API Gateway. However, I keep running into the following behavior when I try to apply my configuration: ``` behavior: behavior creating Lambda function version: InvalidParameterValueException: The function configuration is not valid. Please check the configuration and try again. ``` Hereβs a snippet of my Terraform code: ```hcl resource "aws_lambda_function" "my_function" { function_name = "my_lambda_function" handler = "index.handler" runtime = "nodejs14.x" role = aws_iam_role.lambda_exec.arn source_code_hash = filebase64sha256("./function.zip") } resource "aws_lambda_function_version" "my_function_version" { function_name = aws_lambda_function.my_function.function_name } resource "aws_api_gateway_method" "my_api_method" { rest_api_id = aws_api_gateway_rest_api.my_api.id resource_id = aws_api_gateway_resource.my_resource.id http_method = "GET" authorization = "NONE" request_parameters = { "method.request.querystring.parameter1" = true } } resource "aws_lambda_permission" "allow_api_gateway" { statement_id = "AllowExecutionFromAPIGateway" action = "lambda:InvokeFunction" function_name = aws_lambda_function.my_function.function_name principal = "apigateway.amazonaws.com" source_arn = "arn:aws:execute-api:${var.region}:${data.aws_caller_identity.current.account_id}:${aws_api_gateway_rest_api.my_api.id}/*/*" } ``` I've verified that the Lambda function's IAM role has the necessary execution permissions, and I'm certain that the code in `function.zip` is correct because the function runs fine without versioning. However, when I apply the configuration, it fails at the version creation step. I've tried adding `publish = true` directly in the `aws_lambda_function` resource, but that didn't resolve the scenario either. Am I missing something in the configuration or the order of resource creation? Any guidance on how to properly set up versioning and permissions for AWS Lambda using Terraform would be greatly appreciated. For reference, this is a production mobile app. Any advice would be much appreciated. I'm on Ubuntu 20.04 using the latest version of Hcl. Could this be a known issue? Any pointers in the right direction?