Skip to content

Automated Migration Script for AWS Lambda Python 3.9 End-of-Support

4 minute read
Content level: Intermediate
0

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:

  1. List all Lambda functions using Python 3.9 runtime in the specified region
  2. Update each function to use Python 3.13
  3. 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

An enhanced version of this script is available on GitHub repo to support the following features:

  • Support multiple regions
  • Support all 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. Also, as of September 10, 2025, you will no longer be able to create or update Systems Manager Automation Documents with 'aws:executeScript' actions using Python 3.6, 3.7, 3.8 or 3.9 runtimes. You can use the enhanced version of the script to upgrade Python 3.6, 3.7, 3.8 or 3.9 runtimes all at once.

Related Information

AWS
EXPERT
published 9 months ago4.1K views
2 Comments

This would be a cool script if it actually worked

replied 8 months ago

Works...

You can use the Enhanced version of the script that support multiple region

https://raw.githubusercontent.com/berry2012/Ops-Automation/refs/heads/master/sysops/upgrade-lambda-python/update_lambda_runtime.py

# Setup your python environment and install requirements
python3 -m venv /tmp/.venv
source /tmp/.venv/bin/activate
pip install boto3

# Run the script
python3 update_lambda_runtime.py --regions us-east-1 eu-west-1 ap-southeast-1 eu-west-2 us-west-2 ap-northeast-2 eu-central-1 ap-southeast-2 ap-south-1 sa-east-1 ca-central-1 us-east-2 us-west-1 eu-north-1 --profile default --report update_report.json

Sample outout:

...
Processing region: eu-north-1
Found 1 Python 3.9 functions
Processing: delete-name-tags-eu-north-1-93f3-qdnsa
✓ Updated to python3.13

Completed. Total: 7, Success: 7, Failed: 0
Report saved to update_report.json
AWS
EXPERT
replied 4 months ago