Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Lambda environment variables have a default 4 KB service quota that can't be increased.
If using a large enough number of runtime-loaded secrets it is easy to hit this limit. We did so at around 77 env vars, your mileage may vary depending on the length of env names and ssm paths.
To support an arbitrary number of variables this PR adds dotenv support to the secrets loader.
The loader will gather env from the system environment as usual and then load and merge variables from a dotenv file before retrieving and replacing any secret values necessary from ssm.
Dotenv is used in its immutable mode meaning values in the dotenv file will not replace/overwrite existing variables.
Since this is also the default/suggested behavior when dotenv used in popular frameworks like laravel and symfony there is no risk of conflict if a framwork later reloads the same dotenv file, the retrieved secret values will not be replaced with the ssm paths again.
By default it will look for dotenv files in the
LAMBDA_TASK_ROOT
path, however, you can defineBREF_ENV_PATH
to change this.The file loaded will be determined by looking for an environment name in
BREF_ENV
, falling back to the popularAPP_ENV
. if a value is found we will attempt to load.env.{environment name}
and fallback to.env
else it will attempt to load.env
only, missing files will be safely ignored.These
BREF_ENV_PATH
,BREF_ENV
andAPP_ENV
values would need to remain defined on the lambda itself if required and not in a dotenv file, but all other environment values could be moved to a dotenv.N.B. due to a change required in my related PR on the bref repo unless/until that change is merged you would also need at least one environment variable defined on the lambda itself that has a
bref-ssm:...
value in order to trigger the secrets loading.