99x / 99x/serverless-dynamodb-local
Variable references used in service.provider.stage are literally passed through
- Dominant language
- JavaScript
- Stars
- 621
- Forks
- 232
- PR merge metrics
- No merged PRs in 30d
Description
**Actual Behaviour**
I have following configuration in `serverless.yml`:
```
# plugins
plugins:
- serverless-webpack
- serverless-dynamodb-local
- serverless-offline
custom:
stages:
- local
- development
- production
# default stage/environment
defaultStage: local
...
# aws provider
provider:
name: aws
...
stage: ${opt:stage, self:custom.defaultStage}
....
```
when I use below command, the hooks are not getting registered.
```
npx serverless dynamodb install
```
But, when I use below one, it works:
```
npx serverless --stage local dynamodb install
````
**Expected Behaviour**
If the configuration uses variables, then should be resolved using default stage.
**Steps to reproduce it**
- configure serverless project as per above configuration
- try install command
**LogCat for the issue**
```bash
$ npx serverless dynamodb start
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command webpack
Serverless: Load command dynamodb
Serverless: Load command dynamodb:migrate
Serverless: Load command dynamodb:seed
Serverless: Load command dynamodb:start
Serverless: Load command dynamodb:noStart
Serverless: Load command dynamodb:remove
Serverless: Load command dynamodb:install
Serverless: Load command offline
Serverless: Load command offline:start
Serverless: Invoke dynamodb:start
Serverless: Warning: The command you entered did not catch on any hooks
```
**Screenshots of the issue**
Where-ever possible attach a screenshot of the issue.
**Would you like to work on the issue?**
Yes. I have went through #142, but it not taking care of the above situation.
Below code is used while construction of plugin and thus `service.provider.stage` with variable reference is not resolved correctly. We need to move this post construction of the plugin.
```javascript
const stage = (this.options && this.options.stage) || (this.service.provider && this.service.provider.stage);
if (this.config.stages && !this.config.stages.includes(stage)) {
// don't do anything for this stage
this.hooks = {};
return;
}
```
Contributor guide
Research direction
Start with the plugin-construction code shown in the issue and trace how service.provider.stage is read while hooks are registered. Reproduce the behavior with `npx serverless dynamodb install` and `npx serverless --stage local dynamodb install`; it is done when the variable-based default stage registers the expected hooks without an explicit stage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, javascript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100