• Documentation
  • Pricing
© 2026 Serverless, Inc. All rights reserved.

Framework

  • Overview
  • Documentation
  • Plugins360
  • Pricing

Learn

  • Blog
  • GuidesUpdated
  • Examples240
  • Courses

Resources

  • Support
  • Security
  • Trust Center
  • Status

Community

  • Slack
  • GitHub47k
  • Forum
  • Meetups

Company

  • About
  • Careers
  • Contact
  • Partners

Legal

  • Terms of Service
  • Privacy Policy
  • Trademark
  • DMCA
Serverless Framework Logo

Serverless Framework

Intro
SetupUpgrading To V4ConceptsTutorialAWS CredentialsLicense KeysVerifying Downloads
DeployingPackagingBuildingTestingDev ModeServicesFunctions
OverviewHTTP (API Gateway v2)REST (API Gateway v1)ActiveMQApplication Load BalancerAlexa SkillAlexa Smart HomeCloudWatch EventCloudWatch LogCloudFrontCognito User PoolEventBridge EventIoTIoT Fleet ProvisioningKafkaKinesis & DynamoDBMSKRabbitMQS3ScheduleSNSSQSWebsocket
Layers
OverviewTroubleshooting
Managed InstancesWeb Apps (Lambda Web Functions)Sandboxes (Lambda MicroVMs)MCP ServersAlertsVersion PruningDomainsIAM Function PermissionsParameters
OverviewSelf-reference serverless.ymlServerless CoreEnvironment VariablesCLI OptionsExternal YAML/JSON FilesJavascript propertiesGitDoppler
OverviewS3 ObjectsSSM Parameter Store & Secrets ManagerCloudFormation Stack Outputs
OverviewVaultTerraform State Output
ResourcesComposing ServicesDeployment BucketStateAgent SkillsPython support
OverviewRuntimeGatewayMemoryBrowserCode InterpreterDev Mode
API Gateway Proxy
OverviewGeneral ConfigurationAuthenticationAPI KeysData SourcesResolversPipeline FunctionsSubstitutionsCachingDelta SyncCustom DomainWAFCLI Commands
Deploying SAM/CFN TemplatesWorkflow Tips
OverviewCreating PluginsCLI OutputCustom CommandsCustom VariablesExtending the Configuration schemaExtending and overriding configuration
OverviewDashboardAxiom
Overviewagent docsagent inspectagent setupagent skills installagent skills list / readdeploydeploy functiondeploy listdevdiffinfoinvokeinvoke localloginlogin awslogin aws ssologsmetricspackageplugin installplugin uninstallprintprunereconcileremoverollbackrollback functionusage
OverviewConcepts
OverviewMetricsTracesTroubleshoot
OverviewNode.jsPython
OutputsProviders
OverviewBranch DeploymentsPreview DeploymentsCustom ScriptsTestingPrivate PackagesNotificationsMono ReposDeploy in your own CI/CDBest PracticesTroubleshootingFAQ
OverviewSetupToolsAWS Integration
Serverless.yml Reference
Examples and TutorialsConfiguration Validation
  1. Usage
  2. Variables
  3. CLI Options

CLI Option Variables

A ${opt:<option>} variable reads an option passed to the serverless command, such as --region eu-west-1 in serverless deploy --region eu-west-1. Use it for values that change from one run to the next without editing serverless.yml.

The following serverless.yml adds the Region passed with --region to the function names, and uses us-east-1 when the option isn't passed:

# serverless.yml
service: my-service

provider:
  name: aws
  runtime: nodejs24.x

functions:
  hello:
    handler: handler.hello
    name: my-service-${opt:region, 'us-east-1'}-hello
  world:
    handler: handler.world
    name: my-service-${opt:region, 'us-east-1'}-world
serverless deploy --region eu-west-1

With this command, the functions are named my-service-eu-west-1-hello and my-service-eu-west-1-world.

Option names

${opt:...} reads only options the command accepts: the options every command takes, such as --stage, --region, --aws-profile and --param, the command's own options, and options a plugin declares for the command. Any other option stops the command before it runs, for example Unrecognized option "prefix". Run "serverless deploy --help" for a list of all available options. To pass your own values on the command line, use --param "key=value" and read them with ${param:key}.

<option> is the option name exactly as typed, without the leading dashes: --log-level debug is ${opt:log-level}, and --logLevel is a different option. The name can't be empty: ${opt:} stops the command with a SyntaxError.

Short aliases are separate names. -s prod sets ${opt:s}, not ${opt:stage}, and -r eu-west-1 sets ${opt:r}, not ${opt:region}. To read the stage however it was passed, use ${sls:stage}; pass the Region as --region: with -r, ${aws:region} has no value and the AWS variables don't fall back to provider.region.

Option values

The ${opt:...} variable resolves to the value as the command line gives it:

Command line${opt:...} value
--memory 2048 or --memory=2048'2048', a string
--dry-runtrue
--no-cache${opt:cache} is false
--tag a --tag b['a', 'b'], a list
Option not passedNo value: the default after the comma, otherwise an error

Without a value and without a default, the command stops with Cannot resolve '${opt:...}' variable at '<path>'. For defaults and quoting rules, see Default values.

Related

  • Variables in serverless.yml: syntax, defaults and the other variable sources.
  • Parameters: --param "key=value" values read with ${param:key}, with per-stage defaults in serverless.yml.
  • Serverless Core variables: ${sls:stage} for the stage of the current run.
Edit this page
Prev Environment VariablesNextExternal YAML/JSON Files

Contents

  • CLI Option Variables
  • Option names
  • Option values
  • Related

Related

GuidesPluginsExamplesSlack CommunitySupport