Skip to main content
Glama

aws_elb

Manage AWS Elastic Load Balancers by listing, creating, or deleting them to distribute application traffic across multiple targets.

Instructions

Manage AWS Elastic Load Balancers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYes
regionYes
nameNo
lbTypeNoapplication
schemeNo
subnetsNo
securityGroupsNo
listenersNo
healthCheckNo
tagsNo
targetGroupsNo

Implementation Reference

  • Main handler function for the 'aws_elb' tool. Generates and executes an Ansible playbook to manage AWS Elastic Load Balancers (list, create, delete) based on the provided action and parameters.
    export async function elbOperations(args: ELBOptions): Promise<string> {
      await verifyAwsCredentials();
    
      const { action, region, name, lbType = 'application', scheme, subnets, securityGroups, listeners, healthCheck, tags, targetGroups } = args;
    
      // Determine module based on lbType
      let moduleName: string;
      let infoModuleName: string;
      switch (lbType) {
        case 'application':
          moduleName = 'amazon.aws.elb_application_lb';
          infoModuleName = 'amazon.aws.elb_application_lb_info';
          break;
        case 'network':
          moduleName = 'amazon.aws.elb_network_lb';
          infoModuleName = 'amazon.aws.elb_network_lb_info';
          break;
        case 'classic':
          moduleName = 'amazon.aws.elb_classic_lb';
          infoModuleName = 'amazon.aws.elb_classic_lb_info';
          break;
        default:
          throw new AnsibleError(`Unsupported ELB type: ${lbType}`);
      }
    
      let playbookContent = `---
    - name: AWS ELB ${action} operation (${lbType})
      hosts: localhost
      connection: local
      gather_facts: no
      tasks:`;
      
      switch (action) {
        case 'list':
          playbookContent += `
        - name: List ${lbType} load balancers
          ${infoModuleName}:
            region: "${region}"
          register: elb_info
        
        - name: Display load balancers
          debug:
            var: elb_info`; // Adjust var based on actual module output if needed
          break;
          
        case 'create':
          playbookContent += `
        - name: Create ${lbType} load balancer
          ${moduleName}:
            region: "${region}"
            name: "${name}"
            state: present
    ${formatYamlParams({
      scheme,
      subnets,
      security_groups: securityGroups,
      listeners, // May need adjustment for different LB types
      health_check: healthCheck, // May need adjustment
      tags,
      target_groups: targetGroups // For Application/Network LBs
    })}
          register: elb_result
        
        - name: Display load balancer details
          debug:
            var: elb_result`;
          break;
          
        case 'delete':
          playbookContent += `
        - name: Delete ${lbType} load balancer
          ${moduleName}:
            region: "${region}"
            name: "${name}"
            state: absent
          register: elb_delete
        
        - name: Display deletion result
          debug:
            var: elb_delete`;
          break;
          
        default:
          throw new AnsibleError(`Unsupported ELB action: ${action}`);
      }
      
      // Execute the generated playbook
      return executeAwsPlaybook(`elb-${action}`, playbookContent);
    }
  • Zod schema definition for input validation of the 'aws_elb' tool, including actions (list, create, delete), region, load balancer name, type, and configuration parameters.
    export const ELBSchema = z.object({
      action: ELBActionEnum,
      region: z.string().min(1, 'AWS region is required'),
      name: z.string().optional(),
      lbType: z.enum(['classic', 'application', 'network']).optional().default('application'),
      scheme: z.string().optional(),
      subnets: z.array(z.string()).optional(),
      securityGroups: z.array(z.string()).optional(),
      listeners: z.array(z.any()).optional(), // Consider defining a more specific listener schema
      healthCheck: z.any().optional(), // Consider defining a more specific health check schema
      tags: z.record(z.string()).optional(),
      targetGroups: z.array(z.any()).optional() // Added based on usage in aws.ts. Consider a specific schema.
    });
    
    export type ELBOptions = z.infer<typeof ELBSchema>;
  • Registration of the 'aws_elb' tool in the toolDefinitions map, linking its description, input schema, and handler function.
    aws_elb: {
      description: 'Manage AWS Elastic Load Balancers',
      schema: aws.ELBSchema,
      handler: aws.elbOperations,
    },
  • Shared helper function used by the aws_elb handler (and other AWS handlers) to execute dynamically generated Ansible playbooks for AWS operations, handling temp files and cleanup.
    async function executeAwsPlaybook(
      operationName: string, 
      playbookContent: string, 
      extraParams: string = '',
      tempFiles: { filename: string, content: string }[] = [] // For additional files like templates, policies
    ): Promise<string> {
      let tempDir: string | undefined;
      try {
        // Create a unique temporary directory
        tempDir = await createTempDirectory(`ansible-aws-${operationName}`);
        
        // Write the main playbook file
        const playbookPath = await writeTempFile(tempDir, 'playbook.yml', playbookContent);
        
        // Write any additional temporary files
        for (const file of tempFiles) {
          await writeTempFile(tempDir, file.filename, file.content);
        }
    
        // Build the command
        const command = `ansible-playbook ${playbookPath} ${extraParams}`;
        console.error(`Executing: ${command}`);
    
        // Execute the playbook asynchronously
        const { stdout, stderr } = await execAsync(command);
        
        // Return stdout, or a success message if stdout is empty
        return stdout || `${operationName} completed successfully (no output).`;
    
      } catch (error: any) {
        // Handle execution errors
        const errorMessage = error.stderr || error.message || 'Unknown error';
        throw new AnsibleExecutionError(`Ansible execution failed for ${operationName}: ${errorMessage}`, error.stderr);
      } finally {
        // Ensure cleanup happens even if errors occur
        if (tempDir) {
          await cleanupTempDirectory(tempDir);
        }
      }
    }
  • Utility helper to format AWS parameters as YAML strings for insertion into generated Ansible playbooks, used by the aws_elb handler.
    const formatYamlParams = (params: Record<string, any>, indentation: number = 6): string => {
      // Filter out undefined/null values and format each key-value pair
      return Object.entries(params)
        .filter(([_, value]) => value !== undefined && value !== null)
        .map(([key, value]) => {
          const indent = ' '.repeat(indentation);
          let formattedValue;
          
          // Format based on value type
          if (typeof value === 'string') {
            // Basic YAML string escaping (double quotes, escape backslashes and double quotes)
            formattedValue = `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
          } else if (Array.isArray(value) || typeof value === 'object') {
            // Use JSON.stringify for arrays and objects, assuming it's valid YAML subset
            formattedValue = JSON.stringify(value); 
          } else {
            formattedValue = value; // Numbers, booleans
          }
          return `${indent}${key}: ${formattedValue}`;
        })
        .join('\n');
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure but provides minimal information. 'Manage' implies both read and write operations, but doesn't specify what actions are available (though the schema reveals list/create/delete), what permissions are required, whether operations are idempotent, what happens on failure, or any rate limits. For a tool with 11 parameters including complex nested objects, this is a significant behavioral information gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is maximally concise at just three words. While this represents under-specification rather than ideal conciseness, from a pure structural perspective, it's front-loaded with the core concept and contains zero wasted words. Every word ('Manage', 'AWS', 'Elastic Load Balancers') contributes to the basic understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description is completely inadequate given the tool's complexity. With 11 parameters (including nested objects), no output schema, no annotations, and significant behavioral implications (create/delete operations on AWS infrastructure), a three-word description fails to provide the necessary context. The agent would struggle to use this tool correctly without extensive trial and error or external documentation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage for 11 parameters (including complex nested objects like listeners, healthCheck, and targetGroups), the description provides no parameter guidance whatsoever. The description doesn't mention any parameters, their purposes, or relationships between them. For a tool with this parameter complexity, the description fails to compensate for the complete lack of schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Manage AWS Elastic Load Balancers' is tautological - it essentially restates the tool name 'aws_elb' (AWS Elastic Load Balancer) with the verb 'manage'. While it indicates the general domain, it doesn't specify what management actions are available or distinguish this from other AWS tools like aws_ec2 or aws_vpc. The description lacks the specificity needed for clear tool selection.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides absolutely no guidance on when to use this tool versus alternatives. With 15 sibling tools including other AWS services (aws_ec2, aws_s3, aws_vpc) and infrastructure tools (terraform, cloudformation), there's no indication of when elastic load balancer management is appropriate versus other approaches. The description offers no context about prerequisites, dependencies, or appropriate use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tarnover/mcp-sysoperator'

If you have feedback or need assistance with the MCP directory API, please join our Discord server