Skip to Content

Self variables

self variables read from the current config object. The shorthand form is a bare config path such as ${stage} or ${provider.stage}. Use ${self:...} when you want the source to be explicit.

Shorthand

Use a bare path when the value is already in the config.

stage: ${opt:stage, "dev"} endpoint: https://api.example.com/${stage}

Dot paths work the same way for nested values.

provider: stage: ${opt:stage, "dev"} region: ${opt:region, "us-east-1"} deploymentName: ${provider.stage}-${provider.region}

Explicit self

Use self: when you want the reference source to be obvious.

foo: bar value: ${self:foo}

Nested paths

selfExample: service: billing stage: ${opt:stage, "dev"} apiHost: ${env:DOCS_API_HOST, "localhost"} apiPort: ${env:DOCS_API_PORT, 3000 | Number} baseUrl: https://${selfExample.apiHost}:${selfExample.apiPort} serviceUrl: ${selfExample.baseUrl}/${selfExample.stage}/${selfExample.service} explicitServiceUrl: ${self:selfExample.baseUrl}/${self:selfExample.stage}/${self:selfExample.service}

Bare self references are config-derived values, not external inputs. They can point at values that themselves contain variables, so resolution may take multiple generations.

See resolution model for generation behavior and debug resolution for path-focused troubleshooting.

Last updated on