Skip to content
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

A Python Lambda runtime version #13733

Open
imortkz opened this issue Apr 24, 2024 · 6 comments
Open

A Python Lambda runtime version #13733

imortkz opened this issue Apr 24, 2024 · 6 comments
Labels
feature-request Request a new feature functions Issues tied to the functions category

Comments

@imortkz
Copy link

imortkz commented Apr 24, 2024

Amplify CLI Version

12.11.1

Question

The latest Amplify version still generates v3.8 Python runtime, while it will be EOL soon:

We are ending support for Python 3.8 in Lambda on October 14, 2024. This follows Python 3.8 End-Of-Life (EOL) which is scheduled for October, 2024 [1].

As described in the Lambda runtime support policy [2], end of support for language runtimes in Lambda happens in several stages. Starting on October 14, 2024, Lambda will no longer apply security patches and other updates to the Python 3.8 runtime used by Lambda functions, and functions using Python 3.8 will no longer be eligible for technical support. Also, Python 3.8 will no longer be available in the AWS Console, although you can still create and update functions that use Python 3.8 via AWS CloudFormation, the AWS CLI, AWS SAM, or other tools. Starting February 28, 2025, you will no longer be able to create new Lambda functions using the Python 3.8 runtime. Starting March 31, 2025, you will no longer be able to update existing functions using the Python 3.8 runtime.

We recommend that you upgrade your existing Python 3.8 functions to the latest available Python runtime in Lambda before October 14, 2024.

I can manually update the CloudFormation for lambda function to use v3.10 runtime, but it still will create a v3.8 venv.

Is there any plans to upgrade a default Python runtime?

@imortkz imortkz added pending-triage Issue is pending triage question General question labels Apr 24, 2024
@ykethan
Copy link
Member

ykethan commented Apr 24, 2024

Hey @imortkz, thank you for reaching, marking this as feature-request to upgrade the default python runtime.
From

await execa.command('pipenv install', { cwd: params.srcRoot, stdio: 'inherit' }); // making virtual env in project folder

you should be able to update the runtime in the CloudFormation template and pip file present in the function to 3.10, then run amplify build function to build the function locally before pushing.

@ykethan ykethan added functions Issues tied to the functions category feature-request Request a new feature and removed question General question pending-triage Issue is pending triage labels Apr 24, 2024
@imortkz
Copy link
Author

imortkz commented May 2, 2024

It's supposed to work for new function only?

Tried that with already deployed Python lambda function, didn't work:

Pipfile.lock (a89a07) out of date, updating to (296d86)...
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
✔ Success!
Locking [dev-packages] dependencies...
Updated Pipfile.lock (4575da8dd7dda667a455b5ea8c5b6bf1c2a8fde62a8d4b747ada6e2146296d86)!
Installing dependencies from Pipfile.lock (296d86)...
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
🛑 Could not find a pipenv site-packages directory at /Users/username/.local/share/virtualenvs/function-yFQL_vgG/lib/python3.10/site-packages

Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

Session Identifier: e4c545fe-1701-4253-8053-da203153cc0f

I guess the problem is that virtualenv was already built for Python 3.8

Can you please recommend steps to migrate function from 3.8 to 3.10 properly?

@ykethan
Copy link
Member

ykethan commented May 2, 2024

@imortkz the information is currently documented here: https://docs.amplify.aws/react/build-a-backend/functions/configure-options/#updating-the-runtime
you will need to ensure the python version is installed locally as well for the push to build the function

@softwareengineerprogrammer

@ykethan I am having the same issue, updating the runtime in the cloudformation template json does not appear to be sufficient for python. Can you point us to a guide specifically for python (and not node)?

@hisham
Copy link
Contributor

hisham commented May 13, 2024

+1. Just want to emphasize these dates for the amplify team:

Starting February 28, 2025, you will no longer be able to create new Lambda functions using the Python 3.8 runtime. Starting March 31, 2025, you will no longer be able to update existing functions using the Python 3.8 runtime.

@stratiform
Copy link

stratiform commented Oct 31, 2024

Struggled with this for a while, but I was able to successfully upgrade an existing 3.8 function to 3.11 AND build it using amplify.yml. Note - this was using the AL2023 image, not AL2. Special shout out to this guide for filling in the final pieces:
https://medium.com/@miramnair/aws-amplify-building-a-bedrock-powered-ai-model-with-python-based-lambda-function-556d501f1e5f

Steps:

"Resources": {
  "LambdaFunction": {
      ...
      "Properties": {
        "Runtime": "python3.11",
        "Layers": [],
      }
      ...
    }
}
  • Update the Pipfile to the new runtime
[requires]
python_version = "3.11"
  • rebuild the lambda with the new python3.11 env (I did this using a local Anaconda 3.11 env) to update pip lockfiles
npx amplify build function <function_name>
  • Update my amplify.yml build commands to:
    • install python 3.11
    • install pipenv
    • update PATH to have access to pipenv
    • overwrite python3 and pip3 symlinks
version: 1
backend:
  phases:
    build:
      commands:
        # install python3.11
        # https://plainenglish.io/community/how-to-install-python-3-11-with-pip-on-amazon-linux-2023-9ab2ed
        - sudo dnf install python3.11 -y
        - sudo dnf install python3.11-pip -y
        # install pipenv directly into 3.11
        - pip3.11 install --user pipenv
        # update path
        # https://medium.com/@miramnair/aws-amplify-building-a-bedrock-powered-ai-model-with-python-based-lambda-function-556d501f1e5f
        - export PATH=$PATH:/root/.local/bin
        # update python3.11 symlinks
        # it is not recommended to overwrite the python3 symlink, but it's been working so far, so whatever
        # https://docs.aws.amazon.com/linux/al2023/ug/python.html
        - ln -fs /usr/bin/python3.11 /usr/bin/python3
        - ln -fs /usr/bin/pip3.11 /usr/bin/pip3
        - amplifyPush --simple
  • Committing changes in:
    • cfn templates
    • Pipfile files
    • Pipfile.lock files
    • amplify.yml file

Pushing all those changes FINALLY resulted in a successful build, and the lambdas deployed to the new python 3.11 runtime 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request a new feature functions Issues tied to the functions category
Projects
None yet
Development

No branches or pull requests

5 participants