---
title: "Select Serverless configuration variables using the stage parameter"
description: "How to pass environment parameters to Serverless that depend on the deployment stage"
author: "Bartosz Mikulski"
author_bio: "Principal AI Engineer & MLOps Architect. I bridge the gap between \"it works in a notebook\" and \"it works for 200 million users.\""
author_url: https://mikulskibartosz.name
author_linkedin: https://www.linkedin.com/in/mikulskibartosz/
author_github: https://github.com/mikulskibartosz
canonical_url: https://mikulskibartosz.name/serverless-configuration-variables-for-stage
---

When we use Serverless, the only distinction between production deployment and the testing environment is the configuration we use during the deployment. Serverless makes it relatively easy by providing the "stage" parameter during deployment.

This article will show how to use the stage argument to pick the correct configuration variables for a given environment.

First, we have to define a few custom variables in the yml file. For every variable, we define two values, one with the "dev" key and one with the "prod" key:

```yaml
custom:
  some_parameter:
    prod: prod_value
    dev: dev_value
```

Now, in the environment section of the function configuration, we will extract the correct parameter using the templates two times:

```yaml
functions:
  lambda-handler:
    environment:
      PARAM: ${self:custom.some_parameter.${opt:stage}}
```

We see that the templates are nested. The inner one gets the stage parameter from the options when we run the deploy command. After that, the outer template reads the correct value from the custom variables.

