Skip to content

Instantly share code, notes, and snippets.

@thanakijwanavit
Created May 11, 2023 20:22
Show Gist options
  • Save thanakijwanavit/1441a7cebf38903a9875bfe13acefd3f to your computer and use it in GitHub Desktop.
Save thanakijwanavit/1441a7cebf38903a9875bfe13acefd3f to your computer and use it in GitHub Desktop.
freeze runtime version configuration of all functions in database
import boto3
import itertools
# Initialize the boto3 client for AWS Lambda
lambda_client = boto3.client('lambda', region_name='ap-southeast-1')
# Get the list of all lambda functions
paginator = lambda_client.get_paginator('list_functions')
# response = lambda_client.list_functions(MaxItems=10000)
# print(len(response['Functions']))
response_iterator = paginator.paginate(
PaginationConfig={
'MaxItems': 10000,
'PageSize': 10000,
}
)
functionsList = [r["Functions"] for r in response_iterator]
functions = list(itertools.chain.from_iterable(functionsList))
print(len(functions))
print(functions[0])
# Iterate over all lambda functions
for function in functions:
# Check if the lambda function uses the python 3.8 runtime
# print(function)
if function.get('Runtime') == 'python3.8':
print(f"Updating function: {function['FunctionName']}")
# Update the lambda function to use a new runtime and set the Updateruntime to Manual
lambda_client.put_runtime_management_config(
FunctionName=function['FunctionName'],
UpdateRuntimeOn = 'Manual',
RuntimeVersionArn = 'arn:aws:lambda:ap-southeast-1::runtime:04f6192b7b9a4ad9cb43dc886a5f54868659e182e648f96d6f631cc0cbff8a68'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment