AWS_LAMBDA_JS_RUNTIME - nodejs14.x

It seems that I cannot yet use them though

process.env shows
"AWS_LAMBDA_FUNCTION_VERSION": "$LATEST",
"AWS_EXECUTION_ENV": "AWS_Lambda_nodejs12.x",

netlify.toml
[build]
environment = {AWS_LAMBDA_JS_RUNTIME = 'nodejs14.x', NODE_VERSION = '14'}

I spent a few hours troubleshooting this today as well :slight_smile:

It seems that the AWS_LAMBDA_JS_RUNTIME environment variable has to be specified in the website UI specifically.

Right now even if I specify it for all contexts in netlify.toml it does not get applied:

[build]
# https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript
environment = { NODE_VERSION = "14", AWS_LAMBDA_JS_RUNTIME = "nodejs14.x" }

[context.production.environment]
# https://docs.netlify.com/functions/build-with-javascript/#runtime-settings
# https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
NODE_VERSION = "14"
AWS_LAMBDA_JS_RUNTIME = "nodejs14.x"

[context.deploy-preview.environment]
NODE_VERSION = "14"
AWS_LAMBDA_JS_RUNTIME = "nodejs14.x"

However, if I set the environment variable on the website UI, it does work.
This seems to have an issue with the environment variables from the configuration file.

According to Build environment variables | Netlify Docs

Environment variables set in the UI are also accessible in other environments associated with your site, including serverless functions at execution time, snippet injection during post processing, and more.

Which means only UI environment variables are shared with AWS Lambda, which is a bit weird.

Yup! That is how our system works at the moment - only variables in the UI are “Deployed” with your functions. This allows you to split things like API tokens you need at build time, from things you need at function serve time, so you don’t send “everything” to AWS. Security aside, AWS limits the quantity of environment data you can send to 4kb as concatenated + encoded text (cf Understand the Lambda environment variable size quota) so this split is needed for many customers who need more environment data (plus we include a whole lot by default! see Build environment variables | Netlify Docs for details) than lambdas can have.

Thanks for the detailed answer.

Would it be possible to at least have an option to specify values to “deploy” to AWS Lambda from the configuration file? Not everything is “secret” and it is quite annoying some times to split values between the config, and the UI.
Maybe a special functions_env field or something similar?

Thanks

1 Like

Hey @lambrospetrou,
Yes, agreed that this would be an awesome feature. We have an open request for this internally and I’ve added this thread to that conversation so we can be sure to follow up with you if it ships.

1 Like

Hey there, has setting node version via netlify config file been added since?
I agree, good DX would be a single SPOT (single point of truth) (node versions is certainly no concern for security).

Hey @MentalGear,
You can set NODE_VERSION for your Netlify build in the netlify.toml, yes, but no environment variables in your netlify.toml will make it to your functions unless they are specified in the UI. Hope that helps clear things up :slight_smile:

1 Like

Good news, everybody! We just announced scopes for variables (so you can declare which should not be used for functions): Manage scopes and deploy contexts for environment variables | Netlify Blog

Not quite what you were looking for, @lambrospetrou , but a step in the right direction, we hope!

1 Like