Sign in
agent:

List All AWS Lambda Functions

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

This task displays a list of all AWS Lambda functions in a specified region. The list will include essential details like function name, runtime, and last modified date, aiding in comprehensive management and overview of Lambda functions deployed within your AWS environment.

import boto3 creds = _get_creds(cred_label)['creds'] access_key = creds['username'] secret_key = creds['password'] def get_regions_for_service(): """Retrieve all regions where a specific AWS service is available.""" ec2 = boto3.client('ec2', aws_access_key_id=access_key, aws_secret_access_key=secret_key, region_name="us-east-1") return [region['RegionName'] for region in ec2.describe_regions()['Regions']] def get_lambda_client(region_name=None): """Create a Lambda client for the specified region.""" return boto3.client('lambda', aws_access_key_id=access_key, aws_secret_access_key=secret_key, region_name=region_name) def list_lambda_functions_in_region(region_name): """List all Lambda functions in a specific region, including the region name with each function.""" lambda_client = get_lambda_client(region_name) functions = [] paginator = lambda_client.get_paginator('list_functions') try: for page in paginator.paginate(): functions.extend(page['Functions']) for function in functions: function['Region'] = region_name # Add region information to each function except Exception as e: print(f"An error occurred in {region_name}: {e}") return [] return functions def display_lambda_functions(all_functions): """Display all Lambda functions in a formatted table.""" # Initialize table with the desired structure and headers table = context.newtable() table.title = "AWS Lambda Function Details" table.num_cols = 5 # Number of columns according to headers table.num_rows = 1 # Starts with one row for headers table.has_header_row = True headers = ["Function Name", "Region", "Memory Size", "Runtime", "Last Modified"] # Set headers in the first row for col_num, header in enumerate(headers): table.setval(0, col_num, header) # Populate the table with Lambda function data for row_num, function in enumerate(all_functions, start=1): # Starting from the second row table.num_rows += 1 # Add a row for each function values = [ function['FunctionName'], function['Region'], f"{function['MemorySize']} MB", function['Runtime'], function['LastModified'] ] for col_num, value in enumerate(values): table.setval(row_num, col_num, value) regions = get_regions_for_service() all_functions = [] for region in regions: functions = list_lambda_functions_in_region(region) if functions: all_functions.extend(functions) if all_functions: display_lambda_functions(all_functions) else: print("No Lambda functions found across all regions.") #print(all_functions) # for debugging
copied