Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chalice local should set environment variables from config.json #396

Closed
sbraverman opened this issue Jul 4, 2017 · 2 comments
Closed

Chalice local should set environment variables from config.json #396

sbraverman opened this issue Jul 4, 2017 · 2 comments

Comments

@sbraverman
Copy link

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.

@sbraverman sbraverman changed the title As an engineer, chalice local should set environment variables from config.json Chalice local should set environment variables from config.json Jul 5, 2017
@jamesls
Copy link
Member

jamesls commented Aug 3, 2017

Looks like I forgot to close out this issue. This was added in #411.

@jamesls jamesls closed this as completed Aug 3, 2017
@canfone
Copy link

canfone commented Feb 7, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants