Accessing CLI options with serverless.ts

I’m curious, is it possible to get hold of CLI options like the deployment stage from within the file but outside the configuration?

I.e. I think I could do something like:

stage: '${opt:stage, self:provider.stage}',

within the Serverless configuration definition.

But can I get access to the stage that’s being used outside of the configuration but within the serverless.ts file?


import type { Serverless } from 'serverless/aws';

console.log('${opt:stage, self:provider.stage}'); // how to do this?

const serverlessConfiguration: Serverless = {

Some conversation on this on gitter so copying here for reference.

const serverless = require('serverless');

const sls = new serverless();
console.log(JSON.stringify(sls.processedInput, null, 2));


  "commands": [
  "options": {
    "stage": "production"

However, my concern here is that the structure could change or the processedInput property becomes private in a future release, so I’m interested to know if there are different/better options?