Open imortkz opened 7 months ago
Hey @imortkz, thank you for reaching, marking this as feature-request to upgrade the default python runtime. From https://github.com/aws-amplify/amplify-cli/blob/6340adbb6f02e139128c712719d8054d8fab5ad1/packages/amplify-python-function-runtime-provider/src/util/buildUtils.ts#L10
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.
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?
@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
@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)?
+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.
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": [],
}
...
}
}
[requires]
python_version = "3.11"
npx amplify build function <function_name>
amplify.yml
build commands to:
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
Pushing all those changes FINALLY resulted in a successful build, and the lambdas deployed to the new python 3.11 runtime 😃
Amplify CLI Version
12.11.1
Question
The latest Amplify version still generates v3.8 Python runtime, while it will be EOL soon:
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?