Closed herebebogans closed 4 years ago
Works again if I hack my local serverless/lib/plugins/aws/invokeLocal/index.js
to revert the referenced commit.
@arabold not sure on the best way to fix the hook order?
I've also run into this problem. Any suggestions on how to fix?
@brucekaufman we've replicated the functionality of the plugin using stack exports to set environment variables in helper wrappers around serverless offline and serverless invoke.
You can then do a use "env variable or fallback to cloudformation ref" in serverless variables.
@herebebogans can you provide an example of what you're talking about? I am serverless newbie :)
No worries - I explained it poorly.
Here's an example of referencing a dynamo table with the pattern
custom:
defaults:
dynamo:
myTable: !Ref MyTable
....
dynamo:
myTable: ${env:MY_TABLE, self:custom.defaults.dynamo.myTable}
.....
functions:
myFunction:
handler: index.handler
environment:
MY_TABLE: ${self:custom.dynamo.myTable}
...
resources:
Description: My Stack
Resources:
MyTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: mykey
AttributeType: S
BillingMode: PAY_PER_REQUEST
You then need something to set the MY_TABLE env variable before running sls offline
or sls invoke local
We were using the aws cli along with direnv but now we have wrapper scripts for sls offline / invoke using gulp.
You could also pass it in like
MY_TABLE=dynamotablename sls offline
@arabold Any update, is this repo still maintain?
Sorry for the total lack of communication from my side. I have pushed a version 1.3.1 that should fix this problem by explicitly setting the environment variables before the actual local invoke.
Anyone else noticing that the plugin seems to be broken with
sls invoke local -f <function>
after serverless 1.35.0Ref: Environment variables resolve to [object Object] in the handler. Last serverless release that works is 1.34.1
This commit looks possibly the issue?
https://github.com/serverless/serverless/pull/5565/commits/44a6ac1a101a4ea8aee405bcd1ca538c1b1d88ce