serverless / compose

Orchestrate Serverless Framework in monorepos
https://serverless.com/framework/docs/guides/compose
MIT License
110 stars 15 forks source link

Cannot resolve serverless.yml: "service" property is not accessible #155

Closed gkuga closed 1 year ago

gkuga commented 1 year ago

Are you certain it's a bug?

Are you using the latest version?

Is there an existing issue for this?

Issue description

We want to pass a value from a parameter in serverless-compose.yml to the service property in serverless.yml. It looks like the following

# serverless-compose.yml
services:
  Foo:
    path: bar
    params:
      BazParam: 'baz-val' # This is fixed value
# service.yaml
service: ${param:BazParam}

But we run into this error.

Cannot resolve serverless.yml: "service" property is not accessible (configured behind variables which cannot be resolved at this stage)

Since it is a fixed value passed from serverless-compose.yml, it seems to me that it should be resolved first.

Service configuration (serverless-compose.yml) content

N/A

Command name and used flags

sls Foo:print or sls deploy

Command output

sls Foo:print
Running "serverless" from node_modules
Running "serverless" from node_modules
Environment: darwin, node 16.16.0, framework 3.22.0 (local) 3.22.0v (global), plugin 6.2.2, SDK 4.3.2
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
Cannot resolve serverless.yml: "service" property is not accessible (configured behind variables which cannot be resolved at this stage)
Error: 

Verbose logs are available in ".serverless/compose.log"
mnapoli commented 1 year ago

Hi, this isn't specific to Compose but it isn't possible to use variables in the service: key.

gkuga commented 1 year ago

Thanks for your reply. I will deal with this in a different way.

azelezni commented 11 months ago

Can we please get more information regarding this? Why exactly is it not possible to use variables in the service: key? What is the reasoning behind this?

chrisdugne commented 6 months ago

As a workaround, I use a script to export an environment variable, and this can be used for service. Removing all my other config stuff this is what I use:

.sh:

export SERVICE=xxx
serverless deploy .....

serverless.yml:

service: ${env:SERVICE}