How to do ${opt:stage, "dev"} in a serverless.ts (js) file?

hi there,
just wondering if there are examples of full blown serverless.ts template files. on how to use/reference cli option and environment variables etc.
thanks for help!

Hi. I’ve noticed that the serverless.ts files are very new, so I don’t think there will be many examples. I have just tested your example though, and you can simply wrap it in quotes like this:

environment: {
test: "${opt:stage}"
}

Because it’s a ts file, you can also declare all your options in strings above the full object and then just reference them below, like this:

const myCustomStage = "dev";
const dbName = "mydatabase";

const serverlessConfiguration: Serverless = {
  provider: {
     stage: myCustomStage,
  },
};

You can test your config with the print command. This will interpret your config object and print it to the console.

sls print

2 Likes

Hi @alexvdvalk, thank your very much for your help and examples!

1 Like