From 952d7e615350168e34bd3782501bb906d793a9b5 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Fri, 14 Jan 2022 10:03:35 +0100 Subject: [PATCH 1/4] Update the README for latest serverless v2 and upcoming v3 See https://github.com/serverless/serverless/pull/10495 --- README.md | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index efa5eb7..3aa2e45 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,30 @@ [![Coverage Status](https://coveralls.io/repos/github/neverendingqs/serverless-dotenv-plugin/badge.svg?branch=master)](https://coveralls.io/github/neverendingqs/serverless-dotenv-plugin?branch=master) [![npm version](https://img.shields.io/npm/v/serverless-dotenv-plugin.svg?style=flat)](https://www.npmjs.com/package/serverless-dotenv-plugin) -Preload environment variables into serverless. Use this plugin if you have variables stored in a `.env` file that you want loaded into your serverless yaml config. This will allow you to reference them as `${env:VAR_NAME}` inside your config _and_ it will load them into your lambdas. - -**`serverless>=3.0.0` introduces changes that significantly impacts this plugin. I would love your feedback about this on the [discussion thread](https://github.com/neverendingqs/serverless-dotenv-plugin/discussions/155). See the discussion thread or the FAQ below for details on the impact of how env vars are loaded with `serverless>=2.26.0` and `serverless>=3.0.0`.** +Preload environment variables into serverless. Use this plugin if you have variables stored in a `.env` file that you want loaded into your Lambda functions. ## Do you need this plugin? -Changes in `serverless>=3.0.0` means this plugin can no longer preload environment variables into Serverless. You may want to consider an alternative, such as the one outlined in [`serverless-dotenv-example`](https://github.com/neverendingqs/serverless-dotenv-example). +Serverless Framework can now natively resolve `${env:xxx}` variables from `.env` files by setting [`useDotenv: true` in the configuration](https://www.serverless.com/framework/docs/environment-variables): + +```yaml +useDotenv: true + +provider: + environment: + FOO: ${env:FOO} +``` + +This plugin is still useful if you want to automatically import **all** variables from `.env` into functions: + +```yaml +plugins: + - serverless-dotenv-plugin + +provider: + environment: + # With the plugin enabled, all variables in .env are automatically imported +``` ## Install and Setup @@ -38,18 +55,7 @@ AUTH0_CLIENT_ID=abc12345 AUTH0_CLIENT_SECRET=12345xyz ``` -Once loaded, you can now access the vars using the standard method for accessing ENV vars in serverless: - -```yaml -... -provider: - name: aws - runtime: nodejs6.10 - stage: ${env:STAGE} - region: ${env:AWS_REGION} -... -``` - +When deploying, all the variables listed in `.env` will automatically be available in the deployed Lambda functions. ## Automatic ENV File Resolution From 1e588faf2013482102e077f5117028a6d8b65bbf Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 18 Apr 2022 14:21:13 +0200 Subject: [PATCH 2/4] Update README.md Co-authored-by: Mark Tse --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3aa2e45..a01011e 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ AUTH0_CLIENT_ID=abc12345 AUTH0_CLIENT_SECRET=12345xyz ``` -When deploying, all the variables listed in `.env` will automatically be available in the deployed Lambda functions. +When deploying, all the variables listed in `.env` will automatically be available in the deployed functions. ## Automatic ENV File Resolution From 5f824ba2806e63749be07ed4903255d9ce949078 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 18 Apr 2022 14:21:25 +0200 Subject: [PATCH 3/4] Update README.md Co-authored-by: Mark Tse --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a01011e..4699c80 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,10 @@ [![Coverage Status](https://coveralls.io/repos/github/neverendingqs/serverless-dotenv-plugin/badge.svg?branch=master)](https://coveralls.io/github/neverendingqs/serverless-dotenv-plugin?branch=master) [![npm version](https://img.shields.io/npm/v/serverless-dotenv-plugin.svg?style=flat)](https://www.npmjs.com/package/serverless-dotenv-plugin) -Preload environment variables into serverless. Use this plugin if you have variables stored in a `.env` file that you want loaded into your Lambda functions. +Preload function environment variables into Serverless. Use this plugin if you have variables stored in a `.env` file that you want loaded into your functions. + +This used to also preload environment variables into your `serverless.yml` config, but no longer does with `serverless>=2.26.0. +See [this discussion thread](https://github.com/neverendingqs/serverless-dotenv-plugin/discussions/155) or the FAQ below for details on the impact of how environment variables are loaded with `serverless>=2.26.0` and `serverless>=3.0.0`.** ## Do you need this plugin? From 0c44b3e183694fef831acecf1d278a8007379def Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 18 Apr 2022 14:22:47 +0200 Subject: [PATCH 4/4] Update README.md Co-authored-by: Mark Tse --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4699c80..e7e692e 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,9 @@ provider: FOO: ${env:FOO} ``` -This plugin is still useful if you want to automatically import **all** variables from `.env` into functions: +For more complex situations, you will need to [wire up `dotenv` yourself](https://github.com/neverendingqs/serverless-dotenv-example). + +This plugin is only useful if you want to automatically import **all** variables from `.env` into functions: ```yaml plugins: