AWS has announced the end of support for Python 3.9 in Lambda effective December 15, 2025. This article provides a solution to automatically upgrade Python 3.9 Lambda functions to the latest supported runtime version.
Short description
AWS Lambda's announcement about Python 3.9 end-of-support affects organizations across all scales, from small projects to enterprise deployments. With Python being one of the most popular Lambda runtimes, and Python 3.9 widely adopted since its 2021 Lambda release, many organizations face the challenge of migrating hundreds or thousands of functions across multiple AWS accounts and regions. Manual migration of these functions would typically require 15-30 minutes per function, making it an impractical approach for organizations managing large function portfolios. For instance, an enterprise with 1000 Python 3.9 functions would need approximately 250-500 person-hours for manual migration. This automation solution reduces the migration effort by 97-99%, enabling organizations to efficiently identify and update their Python 3.9 Lambda functions across all accounts and regions, helping them meet the December 15, 2025 deadline with minimal risk and operational overhead.
Prerequisites:
- Install and configure the latest version of the AWS Command Line Interface (AWS CLI).
- Python 3.x installed on your local machine
- Required AWS SDK for Python (Boto3)
- Appropriate AWS IAM permissions to modify Lambda functions
Resolution:
Save the following Python script as update_lambda_runtime.py:
#!/usr/bin/env python3
import boto3
import sys
def main():
region = sys.argv[1] if len(sys.argv) > 1 else 'eu-west-1'
profile = sys.argv[2] if len(sys.argv) > 2 else None
session = boto3.Session(profile_name=profile) if profile else boto3.Session()
lambda_client = session.client('lambda', region_name=region)
if profile:
print(f"Using AWS profile: {profile}")
print(f"Listing Python 3.9 Lambda functions in region: {region}")
# Get Python 3.9 functions
response = lambda_client.list_functions()
py39_functions = [f for f in response['Functions'] if f['Runtime'] == 'python3.9']
if not py39_functions:
print(f"No Python 3.9 Lambda functions found in region {region}")
return
print("Found Python 3.9 functions:")
for func in py39_functions:
print(func['FunctionArn'])
print()
# Update each function
for func in py39_functions:
function_name = func['FunctionName']
print(f"Updating function: {function_name}")
try:
lambda_client.update_function_configuration(
FunctionName=function_name,
Runtime='python3.13'
)
print(f"✓ Successfully updated {function_name} to Python 3.13")
except Exception as e:
print(f"✗ Failed to update {function_name}: {e}")
print()
print("Update process completed.")
if __name__ == "__main__":
main()
Execute the script with your desired AWS region and AWS profile. Note: If no profile is provided, it will use the default AWS credentials.
python3 update_lambda_runtime.py REGION_NAME AWS_PROFILE
Example:
python3 update_lambda_runtime.py ap-southeast-2 staging
The script will:
- List all Lambda functions using Python 3.9 runtime in the specified region
- Update each function to use Python 3.13
- Display the progress and results of the update process
Important Notes:
- Test the script in a non-production environment first
- Review your Lambda functions for Python version-specific code before upgrading
- Consider implementing the upgrade in phases to minimize potential disruptions
- Backup your Lambda function configurations before running the script
- Verify function behavior after the upgrade
The script can be enhanced to:
- Support multiple regions
- Include error handling and rollback capabilities
- Generate detailed reports
- Add dry-run mode for testing
- Include logging functionality
Remember that after December 15, 2025, Python 3.9 runtime will no longer receive security patches or updates, and after February 15, 2026, you won't be able to update existing Python 3.9 functions.
Related Information