How to Enumerate AWS Lambda Functions and Detect Unused Functions

Jan 13, 2024 | Programming

AWS Lambda is a powerful tool that can automate many tasks in the cloud, but what happens when Lambda functions go unused? They can become a burden if not managed well, consuming valuable resources and possibly incurring unnecessary costs. This blog post walks you through the steps to enumerate AWS Lambda functions across all regions and detect dead or unused functions using the List Lambdas project.

Motivation

With the challenge of identifying dead Lambda functions, we encourage you to read our blog post, “The Curse of Dead Lambda Functions,” available at https://epsagon.com/tools/the-curse-of-dead-aws-lambda-functions.

Setup

Getting started is as easy as following these steps:

  • Clone the repository:
  • git clone https://github.com/epsagon/list-lambdas
  • Move into the cloned directory:
  • cd list-lambdas
  • Install the Python dependencies:
  • pip install -r requirements.txt
  • Run the main script:
  • python list_lambdas.py

Using Docker

If you prefer using Docker for your environment, simply follow these steps:

  • Clone the repository:
  • git clone https://github.com/epsagon/list-lambdas
  • Navigate to the directory:
  • cd list-lambdas
  • Build the Docker image:
  • docker build -t list_lambdas:latest .
  • Run the Docker container:
  • docker run --rm -v $HOME/.aws:/root/.aws -t list_lambdas:latest --profile myprofile

Example Outputs

When you execute the commands, the outputs are displayed in various formats:

  • Command Line Interface (CLI):
  • CLI Example Output
  • CSV file:
  • CSV Example Output

Usage

Here are some useful command options to refine your search:

  • Filter Lambda functions inactive in the last 10 days:
  • python list_lambdas.py --inactive-days-filter 10
  • Print extended information to the screen:
  • python list_lambdas.py --all
  • Sort by a specific column (e.g., last invocation time):
  • python list_lambdas.py --sort-by last-invocation
  • Output to a CSV file:
  • python list_lambdas.py --csv lambdas.csv
  • Provide AWS credentials:
  • python list_lambdas.py --token-key-id access_key_id --token-secret secret_access_key

Troubleshooting

If you encounter any issues while setting this up, consider the following troubleshooting tips:

  • Ensure you have the correct AWS permissions for listing Lambda functions.
  • Make sure the AWS CLI is configured properly with the right profile.
  • Check that all dependencies are installed. If there are errors in installations, retry the pip install command.
  • For Docker users, verify that Docker is running and configured properly.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Code Analogy

Think of listing Lambda functions like checking the inventory of a store. Each Lambda function represents a product on the shelf. Over time, some products may become outdated or are simply not bought anymore, leading to an accumulation of unused inventory. Our list-lambdas script helps ‘stock managers’ (developers) identify which products (Lambda functions) should be removed or updated, ensuring that only the most relevant and active items are showcased to the customers (users), optimizing the store’s (cloud service’s) efficiency and cost.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox