How to deal with the problem that build fails when CI / CD of Python Function with AWS Amplify

As the title suggests, I ran into a build failure issue when CI / CDing a Python Function in AWS Amplify.

Conclusion (how to deal with)

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

Problems that occurred

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

Cause

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.

Solution tips

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

How to deal with the problem that build fails when CI / CD of Python Function with AWS Amplify
How to deal with the problem that pandas 1.1.0 or later build fails on Alpine Linux
How to deal with SSL error when connecting to S3 with boto of Python
How to deal with the problem that Japanese characters are garbled when outputting logs using JSON log formatter
[systemd] How to deal with the problem that fancontrol does not work after suspending
The 15th offline real-time I tried to solve the problem of how to write with python
A story about how to deal with the CORS problem
[Introduction to Python] How to get data with the listdir function
How to deal with the phenomenon that Python (Jupyter notebook) executed on WSL becomes Aborted
How to write offline real time I tried to solve the problem of F02 with Python
How to deal with the error that Docker's MySQL container fails to start on Docker Toolbox
How to get the information of organizations, Cost Explorer of another AWS account with Lambda (python)
[VLC] How to deal with the problem that it is not in the foreground during playback
How to deal with python installation error in pyenv (BUILD FAILED)
[Introduction to Python] How to split a character string with the split function
[Python] Explains how to use the format function with an example
How to deal with errors when installing Python and pip with choco
How to deal with the error "Failed to load module" canberra-gtk-module "that appears when you run OpenCV
[Python] How to deal with module errors
The 16th offline real-time how to write problem was solved with Python
How to crop the lower right part of the image with Python OpenCV
[Python] Explains how to use the range function with a concrete example
How to deal with OAuth2 error when using Google APIs from Python
The 16th offline real-time how to write reference problem to solve with Python
[Introduction to Python] How to sort the contents of a list efficiently with list sort
How to create a wrapper that preserves the signature of the function to wrap
[Introduction to Python] How to write a character string with the format function
The 19th offline real-time how to write reference problem to solve with Python
The 15th offline real-time how to write problem was solved with python
[AWS] How to deal with WordPress "An error occurred when cropping an image."
How to deal with errors when hitting pip ②
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
How to solve the problem that only the process remains when you press cross on the imshow screen of OpenCV
When using PyQtGraph with Python Pyside, pay attention to the order of import
Solution to the problem that build does not end when installing OpenCV (PEP517)
How to specify attributes with Mock of python
How to find the coefficient of the trendline that passes through the vertices in Python
[Python] Solution to the problem that elements are linked when copying a list
How to correctly upgrade the software when building Linux (CentOS) with Vagrant ~ Using the example of upgrading from Python 2.7 to Python 3.6 ~
Note: How to get the last day of the month with python (added the first day of the month)
[AWS] Wordpress How to deal with "The response is not a correct JSON response"
[Python] How to deal with the is instance error "is instance () arg 2 must be a type or tuple of types"
How to deal with "^ [[A ^ [[B ^ [[C ^ [[D"] when you press the arrow keys when executing python on mac
How to get a list of files in the same directory with python
[Introduction to Python] How to get the index of data with a for statement
A memo on how to overcome the difficult problem of capturing FX with AI
A memo of misunderstanding when trying to load the entire self-made module with Python3
[AWS] Development environment version that tried to build a Python environment with eb [Elastic Beanstalk]
How to count the number of occurrences of each element in the list in Python with weight
How to get the number of digits in Python
Try to solve the internship assignment problem with Python
The first algorithm to learn with Python: FizzBuzz problem
How to solve the recursive function that solved abc115-D
[Python] How to specify the download location with youtube-dl
[Python] How to deal with pandas read_html read error
Specifies the function to execute when the python program ends
[Python] Summary of how to specify the color of the figure
How to hit the document of Magic Function (Line Magic)
I tried to solve the problem with Python Vol.1
[Python] How to rewrite the table style with python-pptx [python-pptx]
I asked the problem of the tribonacci sequence in C ++ & the number of function calls when writing with the recurrence function (python is also available)