Chalice: Chalice local should set environment variables from config.json

Created on 4 Jul 2017  路  2Comments  路  Source: aws/chalice

Currently

deploying an app creates lambda variables as described in docs:
https://github.com/awslabs/chalice/blob/master/docs/source/topics/configfile.rst

environment_variables - A mapping of key value pairs. These key value pairs will be set as environment variables in your deployed application... 

Problem

when working with Chalice locally, the environment_variables set in the config are not utilized.

Recreating the problem:

Braverman@local:~/Repos $ venv venv-chalice
(venv-chalice) Braverman@local:~/Repos $ chalice new-project fix-local-env-vars
(venv-chalice) Braverman@local:~/Repos $ cd fix-local-env-vars/
(venv-chalice) Braverman@local:~/Repos/fix-local-env-vars $ vim app.py
(venv-chalice) Braverman@local:~/Repos/fix-local-env-vars $ cat app.py
from chalice import Chalice
import os

app = Chalice(app_name='fix-local-env-vars')
app.deug = True


@app.route('/')
def index():
    return {
        'hello': 'world',
        'env_vars': {
            'test': os.environ['TEST'],
            'rick': os.environ['RICK'],
            'py': os.environ['PY']
        }
    }
(venv-chalice) Braverman@local:~/Repos/fix-local-env-vars $ vim .chalice/config.json 
(venv-chalice) Braverman@local:~/Repos/fix-local-env-vars $ cat .chalice/config.json 
{
  "stages": {
    "dev": {
      "api_gateway_stage": "dev"
    }
  },
  "version": "2.0",
  "app_name": "fix-local-env-vars",
  "environment_variables": {
    "TEST": true,
    "RICK": "Morty",
    "PY": "con"
  }
}
(venv-chalice) Braverman@local:~/Repos/fix-local-env-vars $ chalice local
Serving on localhost:8000
127.0.0.1 - - [04/Jul/2017 10:42:01] "GET / HTTP/1.1" 200 -

in a new tab:

(venv-chalice) Braverman@local:~/Repos/fix-local-env-vars $ http localhost:8000
HTTP/1.0 500 Internal Server Error
Content-Length: 80
Content-Type: application/json
Date: Tue, 04 Jul 2017 17:56:41 GMT
Server: BaseHTTP/0.3 Python/2.7.10

{
    "Code": "InternalServerError", 
    "Message": "An internal server error occurred."
}

Expected results:

(venv-chalice) Braverman@local:~/Repos/fix-local-env-vars $ http localhost:8000
HTTP/1.0 200 OK
Content-Length: 78
Content-Type: application/json
Date: Tue, 04 Jul 2017 17:42:01 GMT
Server: BaseHTTP/0.3 Python/2.7.10

{
    "env_vars": {
        "py": "con", 
        "rick": "Morty", 
        "test": "True"
    }, 
    "hello": "world"
}

Solution

Enhance local.py to work with .chalice/config.json

I will be opening a pull-request for review shortly.

feature-request

Most helpful comment

I am running Ubuntu 17.10 and it seems when I run chalice local, the environment_variables mapping is not added to my environment variables. Any ideas? Btw, I'm running Python 3.6.3

All 2 comments

Looks like I forgot to close out this issue. This was added in https://github.com/aws/chalice/pull/411.

I am running Ubuntu 17.10 and it seems when I run chalice local, the environment_variables mapping is not added to my environment variables. Any ideas? Btw, I'm running Python 3.6.3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stannie picture stannie  路  4Comments

jarretraim picture jarretraim  路  3Comments

carlkibler picture carlkibler  路  4Comments

cdalar picture cdalar  路  4Comments

nedlowe picture nedlowe  路  3Comments