• 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 Keys
DeployingPackagingBuildingTestingDev ModeServicesFunctions
OverviewHTTP (API Gateway v2)REST (API Gateway v1)ActiveMQApplication Load BalancerAlexa SkillAlexa Smart HomeCloudWatch EventCloudWatch LogCloudFrontCognito User PoolEventBridge EventIoTIoT Fleet ProvisioningKafkaKinesis & DynamoDBMSKRabbitMQS3ScheduleSNSSQSWebsocket
LayersManaged 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. Plugins
  3. Custom Variables

Custom variable sources in plugins

A Serverless Framework plugin can add its own variable source to serverless.yml, such as ${greeting:world}, next to built-in sources like ${env:...} and ${ssm:...}. Use a custom source to read values from a system the Framework has no source for. The plugin sets configurationVariablesSources in its constructor, with a resolve function for each source name.

This plugin adds the greeting source:

// my-plugin.mjs
export default class MyPlugin {
  constructor() {
    this.configurationVariablesSources = {
      greeting: {
        async resolve({ address }) {
          // In ${greeting:world}, address is 'world'
          return { value: `Hello, ${address}` }
        },
      },
    }
  }
}

A service lists the plugin and uses the source:

# serverless.yml
service: my-service

provider:
  name: aws
  runtime: nodejs24.x

custom:
  message: ${greeting:world}

functions:
  hello:
    handler: handler.hello

plugins:
  - ./my-plugin.mjs

serverless print shows the resolved value:

custom:
  message: Hello, world

The resolve function

To resolve a variable of the source, the Framework calls resolve with one object argument:

PropertyValue
addressThe text after the source name and colon: world in ${greeting:world}.
paramsThe parameters in parentheses as an array of strings: ['one', 'two'] in ${greeting(one, two):world}; otherwise undefined.
optionsThe command's CLI options. options.stage is set only when --stage is passed.
resolveVariable(variable)Resolves another variable, written without ${}, for example resolveVariable('sls:stage').
resolveConfigurationProperty(keys)Returns the resolved value at a path of serverless.yml, given as an array of keys, for example ['provider', 'region'].

resolve returns an object whose value property is the variable's value: a string, number, boolean, object or array. A return value without a value property, such as a plain string, and { value: null } or { value: undefined } count as no value. Then the variable's fallback applies, as in ${greeting:world, 'Hi'}; without a fallback, the command stops with:

Cannot resolve '${greeting:world}' variable at 'custom.message'. No value is available for this variable, and no default value was provided. Please check your variable definitions or provide a default value.

When resolve throws, the fallback doesn't apply: the command stops with an error that starts with Failed to resolve variable 'world' with resolver 'greeting' and ends with the thrown error.

Variable parameters

A variable of a custom source can take parameters in parentheses after the source name. The Framework passes them to resolve in params, trims the spaces around each parameter, and removes the quotes around a quoted one:

# serverless.yml
custom:
  joined: ${greeting(one, "two"):world}
// my-plugin.mjs
export default class MyPlugin {
  constructor() {
    this.configurationVariablesSources = {
      greeting: {
        async resolve({ params = [] }) {
          // ${greeting(one, "two"):world} resolves to 'one,two'
          return { value: params.join(',') }
        },
      },
    }
  }
}

Read other variables and configuration values in a resolver

To build a value from the stage, the Region or another variable, call resolveVariable and resolveConfigurationProperty in resolve:

// my-plugin.mjs
export default class MyPlugin {
  constructor() {
    this.configurationVariablesSources = {
      greeting: {
        async resolve({
          address,
          resolveVariable,
          resolveConfigurationProperty,
        }) {
          const stage = await resolveVariable('sls:stage')
          const region = await resolveConfigurationProperty([
            'provider',
            'region',
          ])
          return { value: `${address} in ${stage} (${region})` }
        },
      },
    }
  }
}

Use resolveVariable('sls:stage') rather than options.stage, which is undefined when the stage comes from provider.stage or the default dev.

When the Framework resolves custom variable sources

The Framework resolves the built-in variable sources first, then loads the plugins listed in plugins, and then resolves the variables of custom sources:

  • Only plugins listed in the service's plugins can add a variable source.
  • In the plugin constructor and in asyncInit(), a variable of a custom source still holds its ${...} text in serverless.service and serverless.configurationInput. In hooks, it holds the resolved value.
  • Variables in values that plugins add with serverless.extendConfiguration() are resolved too, with built-in and custom sources.

Addresses with a colon

The address of a custom source can't contain a colon. The Framework reads ${greeting:a:b} as the resolver a of the source greeting, and stops with:

a resolver of provider greeting not found

Encode the colon in another character, or pass the value as a parameter: ${greeting("a:b"):value}.

Related pages

  • Variables: the built-in variable sources and the ${source:address} syntax
  • Create a plugin
  • Extending and overriding configuration
  • Custom configuration: validate the keys your plugin adds
Edit this page
Prev Custom CommandsNextExtending the Configuration schema

Contents

  • Custom variable sources in plugins
  • The resolve function
  • Variable parameters
  • Read other variables and configuration values in a resolver
  • When the Framework resolves custom variable sources
  • Addresses with a colon
  • Related pages

Related

GuidesPluginsExamplesSlack CommunitySupport