Skip to content

Commit

Permalink
fix: Fix stringifying λ environment variables when using Python2 (aws…
Browse files Browse the repository at this point in the history
  • Loading branch information
Cliffzz authored and jfuss committed Aug 7, 2018
1 parent 8dfc337 commit 546d271
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion samcli/local/lambdafn/env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Supplies the environment variables necessary to set up Local Lambda runtime
"""

import sys


class EnvironmentVariables(object):
"""
Expand Down Expand Up @@ -191,7 +193,12 @@ def _stringify_value(self, value):
result = "false"

# value is a scalar type like int, str which can be stringified
else:
# do not stringify unicode in Py2, Py3 str supports unicode
elif sys.version_info.major > 2:
result = str(value)
elif not isinstance(value, unicode): # noqa: F821 pylint: disable=undefined-variable
result = str(value)
else:
result = value

return result
1 change: 1 addition & 0 deletions tests/unit/local/lambdafn/test_env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def test_must_replace_non_scalar_with_blank_values(self, input):
(False, "false"),
(1234, "1234"),
(3.14, "3.14"),
(u"mystring\xe0", u"mystring\xe0"),
("mystring", "mystring"),
])
def test_must_stringify(self, input, expected):
Expand Down

0 comments on commit 546d271

Please sign in to comment.