agent: |
Qb6YD4ENCAkJIgLiOsnZDelete AWS Lambda Functions
Delete AWS Lambda Functions
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
This task involves safely removing unused or redundant Lambda functions from an AWS account to streamline operations and reduce costs.
inputs
outputs
import boto3
from datetime import datetime, timedelta
# Assuming credentials are securely fetched and stored
creds = _get_creds(cred_label)['creds']
access_key = creds['username']
secret_key = creds['password']
def get_lambda_client(region):
"""Create a Lambda client for a specific region using provided credentials."""
return boto3.client(
'lambda',
region_name=region,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key
)
def delete_lambda_function(function_name, region):
"""Delete a specific Lambda function in a specified region."""
lambda_client = get_lambda_client(region)
try:
response = lambda_client.delete_function(FunctionName=function_name)
print(f"Successfully deleted {function_name} in {region}.")
return response
except Exception as e:
print(f"Failed to delete {function_name} in {region}: {e}")
def delete_unused_lambda_functions(unused_functions):
"""Delete unused Lambda functions from a list of function details."""
for func in unused_functions:
delete_lambda_function(func['FunctionName'], func['Region'])
# Example usage
delete_unused_lambda_functions(unused_functions)
copied