Description:
Runtime Validation for python works by invoking the python executable in the path to check if the local python runtime version matches the required runtime. This validation is done by aws-lambda-builders library.
This relies on how the path is setup to find the appropriate version of python.
ISSUE
(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.
Possibly related: https://github.com/awslabs/aws-lambda-builders/issues/30
WORKAROUND:
Fixing this involves following steps:
export PATH=/usr/bin:$PATH
python --version
2.7.10
(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>
PERMANENT FIX
A more permanent fix is in the works at aws-lambda-builders: https://github.com/awslabs/aws-lambda-builders/pull/35
RELATED GITHUB ISSUE
line in question: https://github.com/awslabs/aws-lambda-builders/blob/develop/aws_lambda_builders/validate.py#L17
I am getting the exact opposite:
$ /usr/bin/sam build --template /home/michaelh/Development/AWS-And-Containers/ohwow/template.yaml --build-dir /home/michaelh/Development/AWS-And-Containers/ohwow/.aws-sam/build
2018-12-08 19:14:51 Found credentials in shared credentials file: ~/.aws/credentials
2018-12-08 19:14:51 Building resource 'HelloWorldFunction'
Build Failed
Error: python executable found in your path does not match runtime.
Expected version: python3.6, Found version: python2.7.
Possibly related: https://github.com/awslabs/aws-lambda-builders/issues/30
On EL7 both Python 2.7 and 3.x executables go into /usr/bin.
$ which python2
/usr/bin/python2
$ which python3
/usr/bin/python3
$ ls -l /usr/bin/python
lrwxrwxrwx. 1 root root 7 Dec 8 17:25 /usr/bin/python -> python2
$ ls -l /usr/bin/python2
lrwxrwxrwx. 1 root root 9 Dec 8 17:25 /usr/bin/python2 -> python2.7
So, no trickery with PATH will help. The base python executable, for backwards compatibility still needs to point to P2. How do I get sam build to pick the correct python3 executable for builds?
@Marakai - Were you able to overcome the hurdle? I am in the exact same situation now.
@Marakai @marakere One absolute way to overcome this is to start a virtualenv with the python interpreter version you want to build for. There is an ongoing effort to fix this.
@Marakai - Appreciate your quick response. Here is what I did, but I am not sure if this is an ideal way for every case.
instead of just going with sam build I added sam build --use-container
Notes for --use-container
This was released with v0.12.0
Closing
Most helpful comment
@Marakai - Appreciate your quick response. Here is what I did, but I am not sure if this is an ideal way for every case.
instead of just going with
sam buildI addedsam build --use-containerNotes for --use-container