Skip to content

fix: helpful error messages when runtime mismatch for build #37

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

Merged
merged 2 commits into from
Nov 26, 2018

Conversation

sriram-mv
Copy link
Contributor

  • When trying to build python2.7 lambda applications from within a sam installation housed in a python3.6 environment, one sees the following error message.
(venv) srirammv@localrainbow:~/sam-app$sam build
2018-11-26 13:40:16 Building resource 'HelloWorldFunction'
Build Failed
Error: python executable found in your path does not match runtime.
 Expected version: python2.7, Found version: python3.6.
 Consider moving python2.7 up path hierarchy.
 Possibly related: https://github.com/awslabs/aws-lambda-builders/issues/30

Fixing this involves following steps:

  • Moving up python executable of version python2.7 on the path
export PATH=/usr/bin:$PATH
(venv) srirammv@localrainbow::~/sam-app$sam build
2018-11-26 13:58:56 Building resource 'HelloWorldFunction'
2018-11-26 13:58:56 Running PythonPipBuilder:ResolveDependencies
2018-11-26 13:58:57 Running PythonPipBuilder:CopySource

Build Succeeded

Built Artifacts  : .aws-sam/build
Built Template   : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Package: sam package --s3-bucket <yourbucket>

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sanathkr
Copy link
Contributor

Is there an integ test that verifies this? If so, can you check the exception message there to double check and make sure the response from sys.stdout gets decoded correctly as utf-8

MESSAGE = "{language} executable found in your path does not " \
"match runtime. " \
"\n Expected version: {required_runtime}, Found version: {found_runtime}. " \
"\n Consider moving {required_runtime} up path hierarchy." \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Consider..." line assumes customers do have Python somewhere else in their path. It is also not obvious how to do this for virtualenv/pyenv users. I would remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -17,6 +17,7 @@ def validate_python_cmd(required_language, required_runtime_version):
"python",
"-c",
"import sys; "
"sys.stdout.write('python' + str(sys.version_info.major) + '.' + str(sys.version_info.minor)); "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha neat ;)

if p.returncode != 0:
raise MisMatchRuntimeError(language=required_language,
required_runtime=required_runtime)
required_runtime=required_runtime,
found_runtime=str(found_runtime.decode('utf-8')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the decode valid in python2.7?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked it with an integ test, and ran it under python2.

under python2, even if its already string and we decode. we get to unicode.

Python 2.7.10 (default, Feb  7 2017, 00:08:15)
Type "copyright", "credits" or "license" for more information.

IPython 5.8.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: mystring="python"

In [2]: type(mystring)
Out[2]: str

In [3]: mystring.decode('utf-8')
Out[3]: u'python'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect

Copy link
Contributor

@sanathkr sanathkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the integ test :)

@sanathkr sanathkr merged commit cf678d6 into aws:develop Nov 26, 2018
sanathkr added a commit that referenced this pull request Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants