{"action":"closed","issue":{"url":"https://api.github.com/repos/Miserlou/Zappa/issues/998","repository_url":"https://api.github.com/repos/Miserlou/Zappa","labels_url":"https://api.github.com/repos/Miserlou/Zappa/issues/998/labels{/name}","comments_url":"https://api.github.com/repos/Miserlou/Zappa/issues/998/comments","events_url":"https://api.github.com/repos/Miserlou/Zappa/issues/998/events","html_url":"https://github.com/Miserlou/Zappa/issues/998","id":241042822,"number":998,"title":"Environment Variable keys are byte array in Python 3.6","user":{"login":"BrianRower-BR","id":29239874,"avatar_url":"https://avatars1.githubusercontent.com/u/29239874?v=3","gravatar_id":"","url":"https://api.github.com/users/BrianRower-BR","html_url":"https://github.com/BrianRower-BR","followers_url":"https://api.github.com/users/BrianRower-BR/followers","following_url":"https://api.github.com/users/BrianRower-BR/following{/other_user}","gists_url":"https://api.github.com/users/BrianRower-BR/gists{/gist_id}","starred_url":"https://api.github.com/users/BrianRower-BR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BrianRower-BR/subscriptions","organizations_url":"https://api.github.com/users/BrianRower-BR/orgs","repos_url":"https://api.github.com/users/BrianRower-BR/repos","events_url":"https://api.github.com/users/BrianRower-BR/events{/privacy}","received_events_url":"https://api.github.com/users/BrianRower-BR/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-07-06T18:18:47Z","updated_at":"2017-07-07T00:12:04Z","closed_at":"2017-07-07T00:12:04Z","body":"## Context\r\nWhen running in python 3 (not an issue in python 2) the environment variables get written to zappa_settings.py as byte arrays rather than strings. Meaning you would have to get your environment variable like this: environ[b'MY_VAR'] rather than like this environ['MY_VAR'].\r\n\r\nThis problem was unmasked by the recent changes in #962 but has likely existed before that. In #962 anything that was an environment_variable in zappa settings (rather than an aws_environment_variable) is no longer written to the aws environment and relies on zappa saving the environment variable to zappa_settings.py and loading that at runtime. \r\n\r\n\r\n## Expected Behavior\r\nWhen zappa_settings has: 'environment_variables': { 'MY_VAR': 'someVal' }\r\nMy code can retrieve the environment variable like so: environ['MY_VAR']\r\n\r\n## Actual Behavior\r\nWhen zappa_settings has: 'environment_variables': { 'MY_VAR': 'someVal' }\r\nMy code can must retrieve the  the environment variable like so: environ[b'MY_VAR']\r\n\r\n## Possible Fix\r\nWhen creating the zappa_settings.py file, decode the byte array back to a string (PR coming soon)\r\n\r\n## Steps to Reproduce\r\nzappa_settings.json:\r\n```\r\n{\r\n    \"dev\": {\r\n        \"apigateway_enabled\": true,\r\n        \"apigateway_description\": \"hello world\", \r\n        \"app_function\": \"main.app\",\r\n        \"aws_region\": \"us-west-2\",\r\n        \"lambda_description\": \"hello world\", \r\n        \"project_name\": \"hello-world\",\r\n        \"s3_bucket\": \"<YOUR BUCKET>\",\r\n        \"timeout_seconds\": 30,\r\n        \"environment_variables\": {\r\n            \"TEST_VAR\": \"TestValue\"\r\n         }\r\n    }\r\n}\r\n\r\n```\r\n\r\nmain.py:\r\n```\r\nimport json\r\nfrom flask import Flask, request, Response\r\nfrom os import environ\r\n\r\napp = Flask(__name__)\r\n\r\n@app.route('/test')\r\ndef stuff():\r\n    for y in environ:\r\n        print (y,':',environ[y])\r\n    return '[{ \"hello\": \"world\"}]', 200\r\n\r\nif __name__ == '__main__':\r\n        app.run(host='0.0.0.0', port=5001)\r\n```\r\n\r\nzappa deploy dev\r\nHit the /test endpoint\r\nExamine the output in cloud watch, the key for TEST_VAR is b'TEST_VAR' rather than 'TEST_VAR'\r\n\r\n## Your Environment\r\nZappa master branch @ b7c16d3ac62aa496dfce8ba533dc64cd20376269\r\nUbuntu 16.04\r\nPython 3.6\r\nargcomplete==1.8.2\r\nbase58==0.2.4\r\nboto3==1.4.4\r\nbotocore==1.5.78\r\ncertifi==2017.4.17\r\nchardet==3.0.4\r\nclick==6.7\r\ndocutils==0.13.1\r\ndurationpy==0.4\r\nFlask==0.12.2\r\nfuture==0.16.0\r\nfutures==3.1.1\r\nhjson==2.0.7\r\nidna==2.5\r\nitsdangerous==0.24\r\nJinja2==2.9.6\r\njmespath==0.9.3\r\nkappa==0.6.0\r\nlambda-packages==0.16.1\r\nMarkupSafe==1.0\r\nplacebo==0.8.1\r\npython-dateutil==2.6.0\r\npython-slugify==1.2.4\r\nPyYAML==3.12\r\nrequests==2.18.1\r\ns3transfer==0.1.10\r\nsix==1.10.0\r\ntoml==0.9.2\r\ntqdm==4.14.0\r\ntroposphere==1.9.4\r\nUnidecode==0.4.21\r\nurllib3==1.21.1\r\nWerkzeug==0.12.2\r\nwsgi-request-logger==0.4.6\r\n\r\n"}}
{"actor":{"display_login":"Miserlou"}}