diff --git a/samcli/local/lambdafn/env_vars.py b/samcli/local/lambdafn/env_vars.py index 6badb4b027c2..33790db10e6c 100644 --- a/samcli/local/lambdafn/env_vars.py +++ b/samcli/local/lambdafn/env_vars.py @@ -2,6 +2,8 @@ Supplies the environment variables necessary to set up Local Lambda runtime """ +import sys + class EnvironmentVariables(object): """ @@ -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 diff --git a/tests/unit/local/lambdafn/test_env_vars.py b/tests/unit/local/lambdafn/test_env_vars.py index 0b67355bc761..6b34ad22e9ab 100644 --- a/tests/unit/local/lambdafn/test_env_vars.py +++ b/tests/unit/local/lambdafn/test_env_vars.py @@ -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):