terraform-aws-next-js icon indicating copy to clipboard operation
terraform-aws-next-js copied to clipboard

Question: Environment variables for Lambda functions

Open PodStuart opened this issue 2 years ago • 2 comments

I note that on your blog post you state that environment variables won't be currently working in the canary version. I just want to clarify what this means exactly.

Does this just mean that there are currently no terraform variables which allow you to configure environment variables on the Lambda functions created during a tf-next deploy?

I'm asking as I am trying to get a Next.js API route to return an environment variable which I've manually configured on the Lambda via the AWS console. I'm doing this using publicRuntimeConfig. I'd have thought this would work OK but I just can't seem to get it to work. I'm probably doing something wrong.

PodStuart avatar Jun 24 '22 07:06 PodStuart

Sorry for the delayed response.

Yes, it is planned that the configuration of environment variables is moved to the tf-next deploy command. Plan is to create a new tf-next env command that is capable of:

  • Add / Remove environment variables
  • Add a VPC-Link
  • Use different IAM role for Lambda

So that you then can run something like tf-next deploy --env testing and the deployment then uses the all settings from the testing environment.


Manually configuring environment variables from the AWS Console should still work at this point from my understanding. Never used publicRuntimeConfig before, need to check if we need to make some adjustments to the build step to support this.

ofhouse avatar Jul 07 '22 16:07 ofhouse

@ofhouse currently it seems like .env file is getting used automatically, can we configure it to use other .env files, like .env.staging or .env.qa ?

iarmankhan avatar Sep 15 '22 10:09 iarmankhan

@ofhouse currently it seems like .env file is getting used automatically, can we configure it to use other .env files, like .env.staging or .env.qa ?

Using

NODE_ENV=staging tf-next build

ochoalopezalfredo avatar Dec 16 '22 06:12 ochoalopezalfredo