AWS Lambda

List and invoke AWS Lambda functions in a chosen region with AWSLambdaTools, gating each operation with enable_ flags.

Enable Agno agents to trigger serverless backend logic and AWS resources without a dedicated API server by using AWS Lambda tools. Use enable_ flag patterns to selectively grant the agent access to only the specific functions it needs.

Prerequisites

  • Set up AWS credentials (AWS CLI, environment variables, or IAM roles)
  • Ensure proper IAM permissions for Lambda operations

from agno.agent import Agent
from agno.tools.aws_lambda import AWSLambdaTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


# Example 1: All functions enabled (default behavior)
agent_full = Agent(
    tools=[AWSLambdaTools(region_name="us-east-1")],  # All functions enabled
    name="Full AWS Lambda Agent",
    description="You are a comprehensive AWS Lambda specialist with all serverless capabilities.",
    instructions=[
        "Help users with all AWS Lambda operations including listing, invoking, and managing functions",
        "Provide clear explanations of Lambda operations and results",
        "Ensure proper error handling for AWS operations",
        "Format responses clearly using markdown",
    ],
    markdown=True,
)

# Example 2: Enable only function listing and invocation
agent_basic = Agent(
    tools=[
        AWSLambdaTools(
            region_name="us-east-1",
            enable_list_functions=True,
            enable_invoke_function=True,
        )
    ],
    name="Lambda Reader Agent",
    description="You are an AWS Lambda specialist focused on reading and invoking existing functions.",
    instructions=[
        "List and invoke existing Lambda functions",
        "Cannot create or modify Lambda functions",
        "Provide insights about function execution and performance",
        "Focus on function monitoring and execution",
    ],
    markdown=True,
)

# Example 3: Enable all functions using 'all=True' pattern
agent_comprehensive = Agent(
    tools=[AWSLambdaTools(region_name="us-east-1", all=True)],
    name="Comprehensive Lambda Agent",
    description="You are a full-featured AWS Lambda manager with all capabilities enabled.",
    instructions=[
        "Manage complete AWS Lambda lifecycle including creation, updates, and deployments",
        "Provide comprehensive serverless architecture guidance",
        "Support advanced Lambda configurations and optimizations",
        "Handle complex serverless workflows and integrations",
    ],
    markdown=True,
)

# Example 4: Invoke-only agent for testing
agent_tester = Agent(
    tools=[
        AWSLambdaTools(
            region_name="us-east-1",
            enable_list_functions=True,
            enable_invoke_function=True,
        )
    ],
    name="Lambda Tester Agent",
    description="You are an AWS Lambda testing specialist focused on safe function execution.",
    instructions=[
        "Test and validate Lambda function execution",
        "Cannot create or delete functions for safety",
        "Provide detailed execution results and performance metrics",
        "Focus on function testing and validation workflows",
    ],
    markdown=True,
)

# Example usage

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    print("=== Basic Lambda Operations Example ===")
    agent_basic.print_response(
        "List all Lambda functions in our AWS account", markdown=True
    )

    print("\n=== Function Testing Example ===")
    agent_tester.print_response(
        "Invoke the 'hello-world' Lambda function with an empty payload and analyze the results",
        markdown=True,
    )

    print("\n=== Comprehensive Management Example ===")
    agent_comprehensive.print_response(
        "Provide an overview of our Lambda environment including function count, runtimes, and recent activity",
        markdown=True,
    )

    # Note: Make sure you have the necessary AWS credentials set up in your environment
    # or use AWS CLI's configure command to set them up before running this script.

Available operations

The toolkit lists function names and invokes existing functions in region_name. It cannot create, update, deploy, or retrieve activity metrics, despite those broader instructions in the cookbook. Listing returns one API response page, not every region or every paginated result.

For the invoke-only configuration in Example 4, change enable_list_functions=True to False. Create a test function first or replace hello-world with an existing function you intend to invoke. The credentials need lambda:ListFunctions for listing and lambda:InvokeFunction on that test function for invocation.

Run the Example

# Clone and setup repo
git clone https://github.com/agno-agi/agno.git
cd agno
git checkout d703c34f3abf3c41275d3fb2da6e0518a8881f24

# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate
uv pip install -U boto3
export OPENAI_API_KEY="your_openai_api_key_here"

python cookbook/91_tools/aws_lambda_tools.py

For details, see AWS Lambda cookbook.