title: AWS SAM local and environment parameters
body: <p>I want to get rid off hardcoded passwords in my lambda that is deployed to AWS. I found I shall modify <code>packaged.yaml</code>:</p>
  
  <pre><code>Parameters:
    DATABASE_URI:
      Description: 'Required. MongoDB connection URL'
      Type: 'String'
  Resources:
    BUDAuthorizeUserHandler:
      Type: AWS::Serverless::Function
      Properties:
        FunctionName: BUDAuthorizeUserHandler
        Handler: src/handlers/users/authorizeUser.handler
        Runtime: nodejs10.x
        Environment:
          Variables:
            MONGODB_URI: !Ref DATABASE_URI
  </code></pre>
  
  <p>This is the usage:</p>
  
  <pre><code>const MONGODB_URI = process.env.MONGODB_URI;
  console.log(MONGODB_URI);
  </code></pre>
  
  <p>So far so good and according to the specification. But I spent two hours trying to make it work locally.</p>
  
  <p>Configuration file <code>env.json</code></p>
  
  <pre><code>{
    "BUDAuthorizeUserHandler": {
       "MONGODB_URI": "mongodb+srv://USER:PASSWORD@HOST/bud?retryWrites=true&amp;w=majority"
     }
  }
  </code></pre>
  
  <p>I tried these options but the environment variable was never defined:</p>
  
  <pre><code>sam local start-api --env-vars env.json
  
  sam local start-api --parameter-overrides ParameterKey=DATABASE_URI,ParameterValue="mongodb+srv://USER:PASSWORD@HOST/bud?retryWrites=true&amp;w=majority"
  </code></pre>
  
  <p>I have walked through these pages:</p>
  
  <p><a href="https://github.com/awslabs/aws-sam-cli/issues/1163" rel="noreferrer">https://github.com/awslabs/aws-sam-cli/issues/1163</a>
  <a href="https://stackoverflow.com/questions/48104665/aws-sam-local-environment-variables">aws-sam-local environment variables</a>
  <a href="https://stackoverflow.com/questions/49266568/how-do-i-specify-template-parameters-when-running-aws-sam-local">How do I specify template parameters when running AWS SAM Local?</a>
  <a href="https://stackoverflow.com/questions/53697215/setting-environmental-variables-with-ref-in-aws-sam">Setting environmental variables with !Ref in AWS SAM?</a></p>
  
  <p>SAM CLI, version 0.39.0</p>
  
  <p>How to make it work? What do I do wrong?</p>