docs/1.5/04-Reference/02-Service-Configuration/02-prisma.yml/03-Using-Variables.md
Variables allow you to dynamically replace configuration values in your service definition file prisma.yml.
To use variables inside prisma.yml, you need to reference the values enclosed in ${} brackets. Inside the brackes, you first need to specify the variable source and the variable name, separated by a colon.
# prisma.yml file
yamlKeyXYZ: ${src:myVariable} # see list of current variable sources below
# this is an example of providing a default value as the second parameter
otherYamlKey: ${src:myVariable, "someDefaultValue"}
Note: The quotes around the default value are required.
A variable source can be either of the following three options:
Note that you can only use variables in property values - not in property keys.
You can reference environment variables inside the service definition file.
When using an environment variable, the value that you put into the bracket is composed of:
env:In the following example, environment variables are used to declare the stage, the cluster and the secret the example service:
service: example
stage: ${env:PRISMA_STAGE}
cluster: ${env:PRISMA_CLUSTER}
secret: ${env:PRISMA_SECRET}
datamodel: database/datamodel.graphql
Note that the CLI will load environment variables from 3 different locations and in the following order:
--dotenv parameter--dotenvargument was omitted, a file called .env in the same directoryYou can recursively reference other property values inside the same prisma.yml file.
When using a recursive self-reference as a variable, the value that you put into the bracket is composed of:
self:If no path is specified, the value of the variable will be the full YAML file.
In the following example, the createCRMEntry function uses the same subscription query as the sendWelcomeEmail function:
subscriptions:
sendWelcomeEmail:
query: database/subscriptions/createUserSubscription.graphql
webhook:
url: ${self:custom.severlessEndpoint}/sendWelcomeEmail
headers: ${self:custom.headers}
createCRMEntry:
query: ${self:functions.subscriptions.sendWelcomeEmail.query}
webhook:
url: ${self:custom.severlessEndpoint}/createCRMEntry
headers: ${self:custom.headers}
custom:
serverlessEndpoint: 'https://bcdeaxokbj.execute-api.eu-west-1.amazonaws.com/dev'
headers:
Authorization: Bearer wohngaeveishuomeiphohph1ls
You can reference CLI options that are passed when invoking a prisma command.
When referencing a CLI option, the value that you put into the bracket is composed of:
opt:As an example, consider this prisma.yml file:
service: example
stage: ${opt:stage}
secret: secret123
datamodel: datamodel.graphql
Now, you can pass a --stage option when running prisma deploy. The CLI will pick the value provided value up and set it as the stage in prisma.yml.
prisma deploy --stage dev