1

I'm having an issue creating two lambda functions. My "controller" function deploys with no issue but my "chunker" function throws an error "Error: At least one field is expected inside environment"

Both functions are nearly identical, with differing zip files and environment variables.


  function_name = format("ancb-chunker-%s",var.env)

  s3_bucket = aws_s3_bucket.ancb["lambda"].id
  s3_key = var.lambda_zip_chunker

  handler = "handler.chunker"
  runtime = "nodejs8.10"

  role = aws_iam_role.lambda_exec.arn

  environment {
      variables = {
          TEST = "yes"
          ORIGINAL_BUCKET = aws_s3_bucket.ancb["original"].id
          TO_PROCESS_BUCKET = aws_s3_bucket.ancb["to-process-prod"].id
          ENVIRONMENT = var.env
          CHUNK_SIZE = 5000
      }
  }
  tags = {
      Environment = var.env
      Terraform = true
  }
}
resource "aws_lambda_function" "ancb_controller" {

  function_name = format("ancb-controller-%s",var.env)

  s3_bucket = aws_s3_bucket.ancb["lambda"].id
  s3_key = var.lambda_zip_controller

  handler = "handler.controller"
  runtime = "nodejs8.10"

  role = aws_iam_role.lambda_exec.arn

  environment {
      variables = {
          DESTINATION_BUCKET = aws_s3_bucket.ancb["destination"].id
          ENVIRONMENT = var.env
          ERROR_BUCKET = aws_s3_bucket.ancb["error"].id
          GEOCODIO_APIKEY = <removed>
          GEOCODIO_ENDPOINT = <removed>
          GEOCODIO_VERSION = "v1.3"
          ORIGINAL_BUCKET = aws_s3_bucket.ancb["original"].id
          SOURCE_BUCKET = aws_s3_bucket.ancb["source"].id
          TO_PROCESS_BUCKET = aws_s3_bucket.ancb["to-process"].id
          WORKING_BUCKET = aws_s3_bucket.ancb["working"].id
      }
  }
  tags = {
      Environment = var.env
      Terraform = true
  }
}

Here is the error received:

Error: At least one field is expected inside environment

  on .terraform/modules/ancb/services/ancb/main.tf line 29, in resource "aws_lambda_function" "ancb_chunker":
  29: resource "aws_lambda_function" "ancb_chunker" {

I expect the code to work for both but in my testing the environment variables that I set for "chunker" don't work. If I put the environment variables for "controller" in the "chunker" variables, I'm able to create the function with no issue...

4
  • 2
    Can you edit your question to include the full error please? Commented Sep 30, 2019 at 8:52
  • I just edited to include the full error. Commented Sep 30, 2019 at 16:12
  • 1
    Does it actually create the controller function properly or is it failing before it gets there? Commented Sep 30, 2019 at 17:06
  • It creates the controller function properly but fails to create the chunker Commented Sep 30, 2019 at 18:24

2 Answers 2

1

Lambdas do not require any environment variables set.

You are however passing in var.env, without knowing more of your issue I would look here.

Sign up to request clarification or add additional context in comments.

1 Comment

But the var.env variable is being passed into the controller function with no problem.
0

This issue was my mistake.. The to process bucket doesn't exist instead it needs to be ["to-process"] TO_PROCESS_BUCKET = aws_s3_bucket.ancb["to-process-prod"].id.

Sorry for wasting everyone's time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.