# Doppler JSON format for AWS SAM CLI

**URL:** <https://community.doppler.com/t/doppler-json-format-for-aws-sam-cli/183>\
**Category:** Need Help\
**Created:** [April 10, 2021, 11:55pm UTC](https://community.doppler.com/t/doppler-json-format-for-aws-sam-cli/183 "2021-04-10T23:55:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rnjai\_Lamba](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/rnjai_lamba/32/94_2.png) [@Rnjai\_Lamba](https://community.doppler.com/u/Rnjai_Lamba)\
**Post date:** [April 10, 2021, 11:55pm UTC](https://community.doppler.com/t/doppler-json-format-for-aws-sam-cli/183/1 "2021-04-10T23:55:07Z")

</div>

Hi, We want to download doppler secrets through the cli in a json file in a specific format -  
{  
“Parameters”: {  
“TABLE\_NAME”: “localtable”,  
“BUCKET\_NAME”: “testBucket”,  
“STAGE”: “dev”  
}  
}

The use case is to send env variables to the AWS SAM cli - `sam local start-api --template samtemplate.yml --env-vars env.json`  
Additionally is there any way to use a standard format .env file to get the CLI working?  
We tried `doppler run -- sam local start-api --template samtemplate.yml` with no success.

Reference - [Invoking functions locally - AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-invoke.html#serverless-sam-cli-using-invoke-environment-file)

---

<div class="post-metadata">

**Author:** ![ryan-blunden](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/ryan-blunden/32/9_2.png) [@ryan-blunden](https://community.doppler.com/u/ryan-blunden)\
**Post date:** [April 11, 2021, 2:38am UTC](https://community.doppler.com/t/doppler-json-format-for-aws-sam-cli/183/2 "2021-04-11T02:38:00Z")

</div>

Hey @Rnjai_Lamba and welcome to the Doppler community!

As long as you have all of the Doppler secrets listed in the `Environment.Variables` section of your SAM template, then `doppler run -- sam local start-api` will work. For example:

```auto
Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      Environment:
        Variables:
          DOPPLER_SECRET:
          OTHER_DOPPLER_SECRET:
          # Every other secret here

```

If for whatever reason you’d like to use the `--env-vars` option instead, you can achieve this using:

```bash
sam local start-api --env-vars <(echo "{\"Parameters\":$(doppler secrets download --no-file --format json)}")

```

Let me know how you go!

---

<div class="post-metadata">

**Author:** ![Rnjai\_Lamba](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/rnjai_lamba/32/94_2.png) [@Rnjai\_Lamba](https://community.doppler.com/u/Rnjai_Lamba)\
**Post date:** [April 11, 2021, 7:40pm UTC](https://community.doppler.com/t/doppler-json-format-for-aws-sam-cli/183/3 "2021-04-11T19:40:10Z")

</div>

Hi Ryan, thanks a lot for the guidance.  
Since our environment variables will keep on changing while we manage them on Doppler, how should we ensure our SAM template gets these secrets listed in the `Environment.Variables` section?

---

<div class="post-metadata">

**Author:** ![ryan-blunden](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/ryan-blunden/32/9_2.png) [@ryan-blunden](https://community.doppler.com/u/ryan-blunden)\
**Post date:** [April 12, 2021, 2:31am UTC](https://community.doppler.com/t/doppler-json-format-for-aws-sam-cli/183/4 "2021-04-12T02:31:41Z")

</div>

This is a good question!

After a bit of experimentation, I think a better (although slightly more complex) solution is to have a script that renders a deployment template with populated environment variables that will be used as a custom template provided to the SAM CLI using the `--template` option.

The workflow would essentially be this:

1. Create deployment template file populated with environment variables form Doppler
2. Execute SAM CLI command (e.g `sam local start-api --template template-deploy.yaml`)
3. Remove `template-deploy.yaml`

An example of a template generator in the wild is [Kubernetes kustomize](https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/).

This means you’ll never have to worry about the list of secrets getting out of sync, and takes care of setting the environment variables for deployment.

Check out this [GitHub Gist](https://gist.github.com/ryan-blunden/a4e7c2e6b0c13e6af9f2d88d4e5a9375) for an implementation starting point and keen to get your feedback.
