I just use a local environment variable export NODE_ENV=local or add it to your .bash_profile for a more permanent solution. Then check it in your code:
if (process.env.NODE_ENV === 'local')...
It would be nice though if there was a built-in env variable in serverless to check against when running invoke local.
I think this is what localstack is aimed at dealing with.
You’d change the endpoint your lambda object points to (to point locally) and then run your SDK commands as normal.
I haven’t tested this, so can’t comment on how effective it is. I would generally think that this is an anti-pattern, because it’s going to greatly complicate your application, and you can never be 100% sure it matches the “real world” AWS API.
I’m also looking for this solution. Does sls offer no way of doing a local lambda.invoke? @mnort9 I’m not sure I understand you solution. Is there an api for local testing, without using localstack?