As the title suggests, I ran into a build failure issue when CI / CDing a Python Function in AWS Amplify.
I was able to pass build by adding the following to amplify.yml in the build settings.
version: 1
backend:
phases:
build:
commands:
#Addition from here>>>
- export BASE_PATH=$(pwd)
- yum install -y gcc openssl-devel bzip2-devel libffi-devel python3.8-pip
- cd /opt && wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz
- cd /opt && tar xzf Python-3.8.2.tgz
- cd /opt/Python-3.8.2 && ./configure --enable-optimizations
- cd /opt/Python-3.8.2 && make altinstall
- pip3.8 install --user pipenv
- ln -fs /usr/local/bin/python3.8 /usr/bin/python3
- ln -fs /usr/local/bin/pip3.8 /usr/bin/pip3
- cd $BASE_PATH
# <<<Added up to here
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
In the CI / CD build phase, it is output that Python 3.8 or higher is required as shown below.
2020-10-27T19:21:49.678Z [INFO]: python3 found but version Python 3.7.4 is less than the minimum required version.
You must have python >= 3.8 installed and available on your PATH as "python3". It can be installed from https://www.python.org/downloads
You must have pipenv installed and available on your PATH as "pipenv". It can be installed by running "pip3 install --user pipenv".
2020-10-27T19:21:49.679Z [WARNING]: ✖ An error occurred when pushing the resources to the cloud
✖ There was an error initializing your environment.
2020-10-27T19:21:49.687Z [INFO]: init failed
2020-10-27T19:21:49.688Z [INFO]: Error: Missing required dependencies to package tatamifmmusiclibrary7312699f
at buildResource (/root/.nvm/versions/node/v10.16.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/build-resources.js:30:11)
at process._tickCallback (internal/process/next_tick.js:68:7)
2020-10-27T19:21:49.699Z [ERROR]: !!! Build failed
2020-10-27T19:21:49.699Z [ERROR]: !!! Non-Zero Exit Code detected
2020-10-27T19:21:49.699Z [INFO]: # Starting environment caching...
2020-10-27T19:21:49.700Z [INFO]: # Environment caching completed
When I do ʻamplify add function` in the Amplify CLI and select Python at runtime, it seems that Python 3.8 is selected internally. On the other hand, Python installed on Amazon Linux 2 used for CI / CD is 3.7.4, so version mismatch will occur.
In my experience, Amplify issues are often raised on GitHub Issues. This matter was already discussed in the following issue.
Amplify can't find Python3.8 on build phase of CI/CD #595
It seems that some people have created custom images, but I don't want to use unofficial images so I decided that it would be better to install Python 3.8 even if it took some time to build. I think that the version of Python installed on Amazon Linux 2 will increase eventually, so it's okay to take a temporary measure.
Recommended Posts