Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The param "dbport" cannot be resolved from CLI options or stage params. If you are using Serverless Framework Compose, make sure to run commands via Compose so that all parameters can be resolved #44

Open
Meddan opened this issue Sep 11, 2023 · 1 comment

Comments

@Meddan
Copy link

Meddan commented Sep 11, 2023

I am trying to pass variables between stacks using Serverless Compose, but I get an error when using that variable to execute a sql migration using the serverless-sequelize-migrations plugin. I am not sure if this is an issue with the plugin, a limitation in Serverless or just me doing something wrong.

Cannot resolve serverless.yml: Variables resolution errored with:
  - Cannot resolve variable at "provider.environment.DB_PORT": The param "dbport" cannot be resolved from CLI options or stage params. If you are using Serverless Framework Compose, make sure to run commands via C
ompose so that all parameters can be resolved
Error:
Error: Command failed: serverless migrations down
    at checkExecSyncError (node:child_process:885:11)
    at execSync (node:child_process:957:15)
    at Scripts.execute (/Users/christoffer/Documents/code/konsult-gpt/node_modules/serverless-plugin-scripts/lib/index.js:113:35)
    at Scripts.runHook (/Users/christoffer/Documents/code/konsult-gpt/node_modules/serverless-plugin-scripts/lib/index.js:108:12)
    at PluginManager.runHooks (/Users/christoffer/Documents/code/konsult-gpt/node_modules/serverless/lib/classes/plugin-manager.js:530:15)
    at runNextTicks (node:internal/process/task_queues:60:5)
    at process.processImmediate (node:internal/timers:447:9)
    at async PluginManager.invoke (/Users/christoffer/Documents/code/konsult-gpt/node_modules/serverless/lib/classes/plugin-manager.js:564:9)
    at async PluginManager.run (/Users/christoffer/Documents/code/konsult-gpt/node_modules/serverless/lib/classes/plugin-manager.js:604:7)
    at async Serverless.run (/Users/christoffer/Documents/code/konsult-gpt/node_modules/serverless/lib/serverless.js:179:5)
    at async /Users/christoffer/Documents/code/konsult-gpt/node_modules/serverless/scripts/serverless.js:834:9

The variable is usable in the stack as I can see it in my environment when deploying a lambda. Is there something I am missing about how serverless handles its context or is this maybe a bug in the plugin?

Relevant snippets from my setup:

serverless_compose.yml:

services:
  service:
    path: service

  migration:
    path: migration
    params:
      dbport: ${service.port}

service/serverless.yml:

resources:
  Outputs:
    port:
      Value: 3306

migration/serverless.yml:

plugins:
  - serverless-sequelize-migrations
  - serverless-plugin-scripts

Provider:
  environment:
        DB_PORT: ${param:dbport}

functions:
  myLambda:
    handler: org.MyHandler
    memorySize: 2048
    timeout: 20

custom:
  scripts:
    hooks:
      'deploy:deploy': serverless migrations down
@Meddan
Copy link
Author

Meddan commented Sep 13, 2023

It seems like this could probably be solved by allowing us to call the script with parameters as those are resolved beforehand. Calling the script like so:

serverless migrations down --DB_PORT ${self:provider.environment.DB_PORT}

Gives the following error (to be expected really):

Error:
Detected unrecognized CLI options: "--DB_PORT".

Error:
Error: Command failed: serverless migrations down --DB_PORT 3306

So the DB_PORT value has resolved correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant