DEV Community

kingyou
kingyou

Posted on

upgrade lambda runtime from python3.9 to python3.12

#!/bin/bash

# AWS CLI configuration - make sure you're authenticated
AWS_PROFILE=${AWS_PROFILE:-default}
AWS_REGION=${AWS_REGION:-us-east-1}

echo "Searching for Lambda functions with Python 3.9 runtime in region $AWS_REGION..."

# Get all Lambda functions with Python 3.9 runtime
functions=$(aws lambda list-functions --region $AWS_REGION --query "Functions[?Runtime=='python3.9'].FunctionName" --output text)

if [ -z "$functions" ]; then
    echo "No Lambda functions with Python 3.9 runtime found in region $AWS_REGION."
    exit 0
fi

echo "Found the following functions using Python 3.9:"
echo "$functions" | tr '\t' '\n'

read -p "Do you want to update these functions to Python 3.12 runtime? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
    echo "Operation cancelled."
    exit 0
fi

# Update each function
for function in $functions; do
    echo "Updating $function to Python 3.12..."
    aws lambda update-function-configuration \
        --function-name "$function" \
        --runtime python3.12 \
        --region $AWS_REGION

    if [ $? -eq 0 ]; then
        echo "Successfully updated $function"
    else
        echo "Failed to update $function"
    fi
done

echo "Update process completed."
Enter fullscreen mode Exit fullscreen mode

Top comments (0)