Skip to content

Instantly share code, notes, and snippets.

@reecestart
Last active January 16, 2024 00:32
Show Gist options
  • Save reecestart/0f613f1fc10f475d909e8107a6e8dcb2 to your computer and use it in GitHub Desktop.
Save reecestart/0f613f1fc10f475d909e8107a6e8dcb2 to your computer and use it in GitHub Desktop.
List all Lambda Functions in all regions with deprecated runtimes using the Python SDK

List all Lambda Functions in all regions with deprecated runtimes using the Python SDK

checkLambdas.py

# Import Python SDK for AWS
import boto3
# Info about source
print("Deprecation Schedule from: https://docs.aws.amazon.com/lambda/latest/dg/runtime-support-policy.html")
print("Current as of Thu 9 Jan 2020")
print("Docs available here if you would like to be notified of new commits: https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/doc_source/runtime-support-policy.md")
# Create the dictionary based on the source
# This could be replaced by requests to future-proof and read from the above URLs
DeprecationScheudle = {'Name': ['Node.js 0.10', 'Node.js 4.3', 'Node.js 6.10', '.NET Core 2.0', '.NET Core 1.0', 'Node.js 8.10'], 'Identifier': ['nodejs', ['nodejs4.3', 'nodejs4.3-edge'], 'nodejs6.10', 'dotnetcore2.0', 'dotnetcore1.0', 'nodejs8.10'], 'End of Life': ['October 31, 2016', 'April 30, 2018', 'April 30, 2019', 'April 30, 2019', 'June 27, 2019', 'December 31, 2019'], 'Deprecation (Create)': ['October 31, 2016', 'December 15, 2018', 'April 30, 2019', 'April 30, 2019', 'June 27, 2019', 'January 6, 2020'], 'Deprecation (Update)': ['October 31, 2016', 'April 30, 2019', 'August 12, 2019', 'May 30, 2019', 'July 31, 2019', 'February 3, 2020']}
# Print the Deprecation Schedule in human readable format
valArray = len(DeprecationScheudle) + 1
for x in range(valArray):
valArray = valArray - 1
print("")
for key, value in DeprecationScheudle.items() :
print (key, ":", value[valArray])
# Create EC2 Client
ec2client = boto3.client('ec2')
# Get all Regions
response = ec2client.describe_regions(
AllRegions=True
)
# Build array for Region Names
regionNames = []
for i in response['Regions']:
regionNames.append(i['RegionName'])
# Create Lambda Function holding array
Lambdas = []
# For each region...
for x in regionNames:
# Create the Lambda client for that region
lambdaclient = boto3.client('lambda', region_name=x)
try:
# List all Functions
response = lambdaclient.list_functions()
except Exception: # For regions not enabled on account e.g. Asia Pacific (Osaka-Local)
pass
# If there are Functions in that Region
if len(response['Functions']) > 0:
# Add them to the Lambdas array
Lambdas.append({'Region': x, 'Functions': response['Functions']})
# Print the Lambdas array for testing
# print(Lambdas)
DeprecatedLambdas = []
# For each region in the Lambdas array
for x in Lambdas:
# Get the Functions for that Region
Functions = x['Functions']
# For each Function
for i in Functions:
# If the Function Runtime is on the Deprication Schedule
if i['Runtime'] in DeprecationScheudle['Identifier']:
# Add Function to Deprecated Lambdas array
DeprecatedLambdas.append({'Region': x['Region'], 'FunctionName': i['FunctionName'], 'FunctionArn': i['FunctionArn'], 'Runtime': i['Runtime']})
print("") # Add a line break for output
print("You have: " + str(len(DeprecatedLambdas)) + " Lambda Functions on the Deprecation Schedule") # Note number of Lambdas with Deprecated Runtimes
print("Would you like to..")
print("Display functions by deprecated runtime[1] or Display functions by region[2]") # Prompt to display by region or runtime
Option = input()
Option = int(Option)
if Option == 1:
for x in DeprecatedLambdas:
print(x['Runtime'] + " | " + x['FunctionName'] + " | " + x['Region'])
elif Option == 2:
for x in DeprecatedLambdas:
print(x['Region'] + " | " + x['FunctionName'] + " | " + x['Runtime'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment