Open edgahan opened 7 years ago
Are you using sls invoke local
or the serverless offline plugin?
Just ran into this with #26 and analyzed it. Neither Serverless nor serverless-offline set the _HANDLER
variable in their local environment, so none of them will work.
For Serverless' invoke local
I can prepare a fix and merge it there - that's easy because it executes a single function only.
For serverless-offline
the problem is not trivial though. Offline loads multiple functions into its process, which means that it might be a bit tricky (if not impossible) to have the environment variable set differently per function.
Maybe serverless-secrets can be changed in a way, that it adds a SECRETS_HANDLER
variable to the lambda functions and presets it with the handler name (that is known implicitly in the service).
However, I'll prepare a fix here in the repo as PR and in Serverless first, so that other plugins that rely on the var will work, but serverless-secrets will be completely independent of the actual AWS lambda environment (BTW: the _HANDLER env var is not documented officially by AWS, see http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html).
@azurelogic Are you ok with such a PR for this plugin?
Also experiencing this with sls invoke local
. Is there a workaround while this PR is pending?
@doublemarked https://github.com/trek10inc/serverless-secrets/pull/30
With this PR I'm able to run sls invoke local
loading secrets successfully.
Together with #27 this makes it work with serverless-webpack and serverless-offline now.
@HyperBrain I merged #27. Sorry again for the delay.
@franciscocpg, @HyperBrain Are you sure that #30 works with projects with multiple functions? Does invoke local only load a single function? Object.keys(secrets.environments)[0]
would not be guaranteed to work otherwise, because the desired function might not be the first element in the array.
@azurelogic
When calling sls invoke local
we pass the function as an argument so I'm almost sure yes.
Let me do some more tests with a few projects that I have that have a lot of functions just to make sure.
I answer you tomorrow, ok?
@franciscocpg Do you have any idea how the same thing can be solved with serverless offline
? That would complete the full local support.
The problem I see there is, that offline runs in one process, so there is no distinction of multiple functions in regards of the environment.
One thought I had was, to use a map in this case and let the client use something else than _HANDLER in case IS_OFFLINE is set to true. But I'm still in the process of evaluating possible solutions.
@HyperBrain I still didn't take a look into serverless-offline
so I'm out of ideas too :disappointed:
to use a map in this case
You mean map the endpoint address to the function handler?
Somehow... I don't have a clear view of that yet - maybe going that way is not feasible.
Hi @HyperBrain Are you managed to solve this issue?
I was able to solve it and use serverless-secrets
with invoke local
and serverless-offline
using these 2 PRs:
Unfortunately it seems that serverless-secrets
repo is not being actively maintained anymore so I'm using my fork for months now (:cry:) .
@franciscocpg Sorry, no I did not have time to investigate further here - currently we do not use serverless-secrets
at work in production projects.
But as I see it, the 2 PRs solve the problem properly. Maybe we can try to get it in here and in offline.
@azurelogic @kcwinner Is the project still actively maintained, so that someone can get the mentioned PR in here?
Hi,
It looks like my process.env._HANDLER is undefined when invoking a lambda locally. This causes this line to break: https://github.com/trek10inc/serverless-secrets/blob/master/client/index.js#L19
Is there something I am missing in my setup? It all seems to work if I tweak that line.