At my previous companies, we used serverless version 2.29.0, we loved the ability to pass in the name of the microservice through the option, e.g.
sls deploy --stage dev --microservice payments
.
And include it to the service name as something like
service: ${self:custom.appName}-${opt.microservice}
to create a different stack to deploy a different set of APIs. So we can deploy different sets of APIs using the same serverless.yml that can reference the function definitions in different files.
Now with v3, we lose the custom option, and have to use param. So the deploy command will become
sls deploy --stage dev --param="microservice=payments"
.
We change the service name to
service: ${self:custom.appName}-${param.microservice}
.
But the param does not get resolved, and is taken literally as ‘${param.microservice}’ which is an invalid name.
Then I tried to use custom
service: ${self:custom.appName}-${self:custom.microservice}
custom:
microservice: {param:microservice, 'default' }
It generates an error:
Error:
Cannot resolve serverless.yml: "service" property is not accessible (configured behind variables which cannot be resolved at this stage)
So it looks like we cannot resolve any parameter/variables before the service name is accessed. I am now out of solutions. I don’t know how else I can dynamically set the service’s name from the input. Does anyone do things in similar way, and has a solution?
I don’t want to create a different serverlss.yml for different set of APIs, like serverless-orders.yml
, serverless-customers.yml
, etc. and use different config file to deploy different set of APIs.
I tried downgraded serverless back to 2.29.0, but it only supports node up to 14. I am using node 16 in my project.
Thank you for your help!