# How do I specify the stage in a function so I can deploy to stage and production

**URL:** <https://forum.serverless.com/t/how-do-i-specify-the-stage-in-a-function-so-i-can-deploy-to-stage-and-production/2297>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [July 15, 2017, 1:06pm UTC](https://forum.serverless.com/t/how-do-i-specify-the-stage-in-a-function-so-i-can-deploy-to-stage-and-production/2297 "2017-07-15T13:06:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![noppanit](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/noppanit/32/803_2.png) [@noppanit](https://forum.serverless.com/u/noppanit)\
**Post date:** [July 15, 2017, 1:06pm UTC](https://forum.serverless.com/t/how-do-i-specify-the-stage-in-a-function-so-i-can-deploy-to-stage-and-production/2297/1 "2017-07-15T13:06:36Z")

</div>

I’m super new to serverless. I would like to be able to deploy the same function but different AWS account profile. Stage and Production.

This is my function configuration

functions:  
sls-chameleon-ci:  
memorySize: 256  
description: Chameleon transform pageview event to Atlas  
handler: chameleon-lambda.handler  
timeout: 120s  
events:  
- stream:  
type: kinesis  
arn:   
batchSize: 100  
startingPosition: LATEST  
environment:  
SQS\_QUEUE:   
tags:  
BillingBrandCode: CIA

I have this function that I use this command to deploy.

…/node\_modules/.bin/serverless deploy --stage n -v --aws-profile nonproduction

How do I deploy the same function that could deploy to my production AWS account with production Kinesis and SQS. Right now I just hardcode that in the YAML file.

---

<div class="post-metadata">

**Author:** ![tomwilderspin](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/tomwilderspin/32/164_2.png) [@tomwilderspin](https://forum.serverless.com/u/tomwilderspin)\
**Post date:** [July 15, 2017, 3:46pm UTC](https://forum.serverless.com/t/how-do-i-specify-the-stage-in-a-function-so-i-can-deploy-to-stage-and-production/2297/2 "2017-07-15T15:46:34Z")

</div>

Hey,

You can do this using the profile flag on the cli for example:  
serverless deploy --aws-profile prodProfile

Loads more methods and explaination can be found here:

> **[Serverless Framework - AWS Lambda Guide - Credentials](https://www.serverless.com/framework/docs/providers/aws/guide/credentials/)**
>
> How to set up the Serverless Framework with your Amazon Web Services credentials

Per account creds info:

> **[Serverless Framework - AWS Lambda Guide - Credentials](https://www.serverless.com/framework/docs/providers/aws/guide/credentials/)**
>
> How to set up the Serverless Framework with your Amazon Web Services credentials

Hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![noppanit](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/noppanit/32/803_2.png) [@noppanit](https://forum.serverless.com/u/noppanit)\
**Post date:** [July 15, 2017, 7:12pm UTC](https://forum.serverless.com/t/how-do-i-specify-the-stage-in-a-function-so-i-can-deploy-to-stage-and-production/2297/3 "2017-07-15T19:12:11Z")

</div>

Thanks for your reply. So, do I create another function for that? Or I can reuse the same function? Because the prod account has different Kinesis stream name and SQS

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [July 16, 2017, 3:00am UTC](https://forum.serverless.com/t/how-do-i-specify-the-stage-in-a-function-so-i-can-deploy-to-stage-and-production/2297/4 "2017-07-16T03:00:08Z")

</div>

Don’t hard code stuff into your application or your `serverless.yaml`. The simplest solution is to add:

```auto
custom:
  stage: "${opt:stage, self:provider.stage}"

```

then include `${self:custom.stage}` as part of the resource name. You can do a similar thing with region if you need to deploy the same stage to different regions.

Then pass the relevant information to your functions using environment variables.

---

<div class="post-metadata">

**Author:** ![noppanit](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/noppanit/32/803_2.png) [@noppanit](https://forum.serverless.com/u/noppanit)\
**Post date:** [July 16, 2017, 12:10pm UTC](https://forum.serverless.com/t/how-do-i-specify-the-stage-in-a-function-so-i-can-deploy-to-stage-and-production/2297/5 "2017-07-16T12:10:37Z")

</div>

Thanks! I think I’m starting to get it now.

---

<div class="post-metadata">

**Author:** ![kariem](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/kariem/32/806_2.png) [@kariem](https://forum.serverless.com/u/kariem)\
**Post date:** [July 18, 2017, 11:55am UTC](https://forum.serverless.com/t/how-do-i-specify-the-stage-in-a-function-so-i-can-deploy-to-stage-and-production/2297/6 "2017-07-18T11:55:48Z")

</div>

From what I see, you can put the stage directly into the provider section and it will be used in naming. However, you can provide the default stage in the custom section.

I’ve adapted the example from [the documentation](https://serverless.com/framework/docs/providers/aws/guide/credentials/#per-stage-profiles "AWS - Credentials: Per Stage Profiles") as follows:

```auto
provider:
  name: aws
  ...
  stage: ${opt:stage, self:custom.defaultStage}

custom:
  defaultStage: dev

```

The corresponding cloud formation stack will then have the name `<service>-<stage>` and the stage will default to `dev`, if no stage is provided.
