Serverless-offline: Passing a custom option

Created on 18 Aug 2019  路  8Comments  路  Source: dherault/serverless-offline

Hello!
Thanks for this awesome plugin.

In my serverless.yml I have two different options for stages:

  • stage: for domains
  • stage_rcs: for resources

and I would like to pass them as options so I run this command: sls offline --stage stage_option --stage_rcs stage_rcs_option; However, when the plugin starts, it works fine - no exceptions and no warnings. but as soon as I request some URL, it throws this warning:

 A valid option to satisfy the declaration 'opt:stage_rcs' could not be found.

I guess it's not passed as an option for each invocation or so.

How can I do this?

Thanks in advance

bug python

Most helpful comment

_update_: I rewrote the (fairly buggy) python handling code, and it's running great locally. your specific issue should be fixed soon as well.

All 8 comments

hey @AhmedNourJamalElDin

there is no option: --stage_rcs. what problem are you trying to solve?

Hi @dnalborczyk
I would like to add my custom option and I call it stage_rcs. it's not about specific option called stage_rcs but any custom option. I pass this option to serverless.yml in the command sls offline --stage_rcs some_value to add some important configuration based on the value of my custom option stage_rcs.

I add it to serverless.yml like this: stage_rcs: ${opt:stage_rcs}

to what is stage_rcs assigned to in serverless.yml? could you post more relevant information of your serverless.yml file?

@AhmedNourJamalElDin

maybe better: could you create a small repository which outlines your problem?

It's so simple, just add this to the provide in serverless.yml:

   test_var: ${opt:test_var}

and pass it as follows: sls offline --test_var some_val

and try it

here is the repo.

thank you for the repository @AhmedNourJamalElDin , that made it more clear. it was hard to guess that you are using python.

this seems like a bug on our side, in that we are not passing any options (except --stage) to the python process. this should be a fairly easy fix though.

btw, I don't think this has any use case:

provider:
  test_var: ${opt:test_var}

you would probably use it this way, e.g.

provider:
  stage: ${opt:test_var}

like I said, this should work now:

provider:
  stage: ${opt:stage}

_update_: I rewrote the (fairly buggy) python handling code, and it's running great locally. your specific issue should be fixed soon as well.

hey @AhmedNourJamalElDin

the python handling refactoring is deployed in the latest v6-alpha. there's still a bit to do: e.g. error handling, how to handle python print, and there might be problems running on windows.

option passing should now work automatically, since we're running the process directly.

give it a try, and if you have any problems or suggestions, feel free to re-open this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aldofunes picture aldofunes  路  3Comments

Dong9769 picture Dong9769  路  4Comments

yareyaredesuyo picture yareyaredesuyo  路  4Comments

conradoramalho picture conradoramalho  路  3Comments

Rafaelsk picture Rafaelsk  路  4Comments