Skip to main content
Glama

aws_lambda

Manage AWS Lambda functions by listing, creating, updating, deleting, or invoking serverless functions to automate cloud operations.

Instructions

Manage AWS Lambda functions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYes
regionYes
nameNo
zipFileNo
s3BucketNo
s3KeyNo
functionCodeNo
runtimeNo
handlerNo
roleNo
descriptionNo
timeoutNo
memorySizeNo
environmentNo
tagsNo
payloadNo

Implementation Reference

  • Main handler function for aws_lambda tool. Generates dynamic Ansible playbooks using amazon.aws.lambda module to perform operations like list, create/update, delete, invoke on AWS Lambda functions.
    export async function lambdaOperations(args: LambdaOptions): Promise<string> {
      await verifyAwsCredentials();
    
      const { action, region, name, zipFile, s3Bucket, s3Key, functionCode, runtime, handler, role, description, timeout, memorySize, environment, tags, payload } = args;
    
      const tempFiles: { filename: string, content: string }[] = [];
      let codeParams = '';
      let zipPath: string | undefined; // To track zip file for cleanup
    
      if (zipFile) {
        // Assuming zipFile is a path accessible to the server running this code
        codeParams = `zip_file: "${zipFile}"`; 
      } else if (s3Bucket && s3Key) {
        codeParams = `s3_bucket: "${s3Bucket}"\n        s3_key: "${s3Key}"`;
      } else if (functionCode) {
        // If code is provided directly, write it to a temp file and prepare to zip it
        const codeFilename = 'lambda_function.py'; // Assuming Python, adjust if needed
        tempFiles.push({ filename: codeFilename, content: functionCode });
        
        // We'll need to zip this file before executing Ansible
        // This requires the 'zip' utility on the server
        zipPath = 'lambda_function.zip'; // Relative path within temp dir
        codeParams = `zip_file: "${zipPath}"`; 
      } else if (action === 'create' || action === 'update') {
        throw new AnsibleError('Lambda code source (zipFile, S3, or functionCode) must be provided for create/update actions.');
      }
    
      let playbookContent = `---
    - name: AWS Lambda ${action} operation
      hosts: localhost
      connection: local
      gather_facts: no
      tasks:`;
      
      switch (action) {
        case 'list':
          playbookContent += `
        - name: List Lambda functions
          amazon.aws.lambda_info:
            region: "${region}"
          register: lambda_info
        
        - name: Display Lambda functions
          debug:
            var: lambda_info.functions`;
          break;
          
        case 'create':
        case 'update':
          playbookContent += `
        - name: ${action === 'create' ? 'Create' : 'Update'} Lambda function
          amazon.aws.lambda:
            region: "${region}"
            name: "${name}"
            state: present
            ${codeParams} # Use determined code source params
    ${formatYamlParams({
      runtime,
      handler,
      role,
      description,
      timeout,
      memory_size: memorySize,
      environment_variables: environment,
      tags
    })}
          register: lambda_result
        
        - name: Display function details
          debug:
            var: lambda_result`;
          break;
          
        case 'delete':
          playbookContent += `
        - name: Delete Lambda function
          amazon.aws.lambda:
            region: "${region}"
            name: "${name}"
            state: absent
          register: lambda_delete
        
        - name: Display deletion result
          debug:
            var: lambda_delete`;
          break;
          
        case 'invoke':
          playbookContent += `
        - name: Invoke Lambda function
          amazon.aws.lambda_invoke:
            region: "${region}"
            function_name: "${name}"
            invocation_type: RequestResponse # Or Event, DryRun
    ${formatYamlParams({ payload })}
          register: lambda_invoke
        
        - name: Display invocation result
          debug:
            var: lambda_invoke`;
          break;
          
        default:
          throw new AnsibleError(`Unsupported Lambda action: ${action}`);
      }
    
      // Special handling for zipping code before executing Ansible
      let tempDir: string | undefined;
      try {
        tempDir = await createTempDirectory(`ansible-aws-lambda-${action}`);
        
        // Write the main playbook file
        const playbookPath = await writeTempFile(tempDir, 'playbook.yml', playbookContent);
        
        // Write any additional temporary files (like the function code)
        for (const file of tempFiles) {
          await writeTempFile(tempDir, file.filename, file.content);
        }
    
        // If we need to zip the code, do it now using execAsync
        if (zipPath && tempFiles.some(f => f.filename === 'lambda_function.py')) {
          const codeFilePath = `${tempDir}/lambda_function.py`;
          const zipFilePath = `${tempDir}/${zipPath}`;
          const zipCommand = `zip -j "${zipFilePath}" "${codeFilePath}"`; 
          console.error(`Executing: ${zipCommand}`);
          await execAsync(zipCommand, { cwd: tempDir }); // Run zip in the temp directory
        }
    
        // Build the final Ansible command
        const command = `ansible-playbook ${playbookPath}`;
        console.error(`Executing: ${command}`);
    
        // Execute the playbook asynchronously
        const { stdout, stderr } = await execAsync(command);
        
        return stdout || `Lambda ${action} completed successfully (no output).`;
    
      } catch (error: any) {
        const errorMessage = error.stderr || error.message || 'Unknown error';
        throw new AnsibleExecutionError(`Ansible execution failed for lambda-${action}: ${errorMessage}`, error.stderr);
      } finally {
        if (tempDir) {
          await cleanupTempDirectory(tempDir);
        }
      }
    }
  • Zod schema (LambdaSchema) defining the input parameters and validation for the aws_lambda tool.
    export const LambdaSchema = z.object({
      action: LambdaActionEnum,
      region: z.string().min(1, 'AWS region is required'),
      name: z.string().optional(),
      zipFile: z.string().optional(),
      s3Bucket: z.string().optional(),
      s3Key: z.string().optional(),
      functionCode: z.string().optional(),
      runtime: z.string().optional(),
      handler: z.string().optional(),
      role: z.string().optional(),
      description: z.string().optional(),
      timeout: z.number().optional(),
      memorySize: z.number().optional(),
      environment: z.record(z.string()).optional(),
      tags: z.record(z.string()).optional(),
      payload: z.any().optional() // Added based on usage in aws.ts. Payload structure varies.
    });
    
    export type LambdaOptions = z.infer<typeof LambdaSchema>;
  • Tool registration in the central toolDefinitions map used by the MCP server to handle tool calls.
    aws_lambda: {
      description: 'Manage AWS Lambda functions',
      schema: aws.LambdaSchema,
      handler: aws.lambdaOperations,
    },
Behavior1/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 offers none. It doesn't mention that this is a mutation tool (create/update/delete actions), doesn't discuss authentication requirements, rate limits, error handling, or what happens during operations like 'delete' or 'invoke'. The single word 'manage' provides zero behavioral context.

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, though this conciseness comes at the cost of being severely under-specified. There's no wasted language or unnecessary elaboration, making it technically efficient if inadequate.

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?

For a complex tool with 16 parameters, no annotations, no output schema, and multiple possible actions (including destructive operations like delete), the description is completely inadequate. It provides no information about what the tool actually does, how to use it, what parameters mean, or what to expect as results.

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

Parameters1/5

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

With 16 parameters and 0% schema description coverage, the description provides no information about any parameters. It doesn't explain what the 'action' enum values do, what 'region' should contain, or how parameters like 'zipFile', 's3Bucket', 'functionCode' relate to each other. The description fails completely to compensate for the schema's lack of parameter 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 Lambda functions' is a tautology that essentially restates the tool name 'aws_lambda' without adding meaningful specificity. It uses a generic verb 'manage' that doesn't distinguish what specific operations are available or how this differs from sibling AWS tools like aws_ec2 or aws_s3.

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 about when to use this tool versus alternatives. There's no mention of prerequisites, appropriate contexts, or differentiation from the 16 sibling tools listed, particularly other AWS services that might overlap in functionality.

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