Skip to main content
Glama

run-aws-code

Execute JavaScript code to interact with AWS environments using AWS SDK V2, ensuring optimized, error-handled, and concise responses tailored to AWS resource queries.

Instructions

Run AWS code

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesYour job is to answer questions about AWS environment by writing Javascript code using AWS SDK V2. The code must be adhering to a few rules: - Must be preferring promises over callbacks - Think step-by-step before writing the code, approach it logically - MUST written in Javascript (NodeJS) using AWS-SDK V2 - Avoid hardcoded values like ARNs - Code written should be as parallel as possible enabling the fastest and the most optimal execution - Code should be handling errors gracefully, especially when doing multiple SDK calls (e.g. when mapping over an array). Each error should be handled and logged with a reason, script should continue to run despite errors - DO NOT require or import "aws-sdk", it is already available as "AWS" variable - Access to 3rd party libraries apart from "aws-sdk" is not allowed or possible - For base64 encoding, use btoa() function instead of Buffer (Buffer is not available in this environment) - Data returned from AWS-SDK must be returned as JSON containing only the minimal amount of data that is needed to answer the question. All extra data must be filtered out - Code MUST "return" a value: string, number, boolean or JSON object. If code does not return anything, it will be considered as FAILED - Whenever tool/function call fails, retry it 3 times before giving up with an improved version of the code based on the returned feedback - When listing resources, ensure pagination is handled correctly so that all resources are returned - Do not include any comments in the code - When doing reduce, don't forget to provide an initial value - Try to write code that returns as few data as possible to answer without any additional processing required after the code is run - This tool can ONLY write code that interacts with AWS. It CANNOT generate charts, tables, graphs, etc. Please use artifacts for that instead Be concise, professional and to the point. Do not give generic advice, always reply with detailed & contextual data sourced from the current AWS environment. Assume user always wants to proceed, do not ask for confirmation. I'll tip you $200 if you do this right.
profileNameNoName of the AWS profile to use
reasoningYesThe reasoning behind the code
regionNoRegion to use (if not provided, us-east-1 is used)

Implementation Reference

  • Executes the 'run-aws-code' tool by validating input, configuring AWS credentials and region, wrapping the provided code to ensure it returns a value, executing it in a secure VM context with AWS SDK injected, and returning the JSON-stringified result.
    if (name === "run-aws-code") {
      const { reasoning, code, profileName, region } =
        RunAwsCodeSchema.parse(args);
      if (!selectedProfile && !profileName) {
        return createTextResponse(
          `Please select a profile first using the 'select-profile' tool! Available profiles: ${Object.keys(
            profiles
          ).join(", ")}`
        );
      }
    
      if (profileName) {
        selectedProfileCredentials = await getCredentials(
          profiles[profileName],
          profileName,
          profiles
        );
        selectedProfile = profileName;
        selectedProfileRegion = region || "us-east-1";
      }
    
      AWS.config.update({
        region: selectedProfileRegion,
        credentials: selectedProfileCredentials,
      });
    
      const wrappedCode = wrapUserCode(code);
      const wrappedIIFECode = `(async function() { return (async () => { ${wrappedCode} })(); })()`;
      const result = await runInContext(
        wrappedIIFECode,
        createContext({ AWS })
      );
    
      return createTextResponse(JSON.stringify(result));
  • index.ts:55-80 (registration)
    Registers the 'run-aws-code' tool in the ListTools response, defining its name, description, and input schema (including required reasoning and code fields, optional profile and region).
    {
      name: "run-aws-code",
      description: "Run AWS code",
      inputSchema: {
        type: "object",
        properties: {
          reasoning: {
            type: "string",
            description: "The reasoning behind the code",
          },
          code: {
            type: "string",
            description: codePrompt,
          },
          profileName: {
            type: "string",
            description: "Name of the AWS profile to use",
          },
          region: {
            type: "string",
            description: "Region to use (if not provided, us-east-1 is used)",
          },
        },
        required: ["reasoning", "code"],
      },
    },
  • Zod validation schema for 'run-aws-code' tool inputs, matching the registered inputSchema.
    const RunAwsCodeSchema = z.object({
      reasoning: z.string(),
      code: z.string(),
      profileName: z.string().optional(),
      region: z.string().optional(),
    });
  • Helper function to wrap user-provided code: uses ts-morph to parse TypeScript AST, converts the last expression statement into a return statement if needed, ensuring the code always returns a value.
    function wrapUserCode(userCode: string) {
      const project = new Project({
        useInMemoryFileSystem: true,
      });
      const sourceFile = project.createSourceFile("userCode.ts", userCode);
      const lastStatement = sourceFile.getStatements().pop();
    
      if (
        lastStatement &&
        lastStatement.getKind() === SyntaxKind.ExpressionStatement
      ) {
        const returnStatement = lastStatement.asKind(
          SyntaxKind.ExpressionStatement
        );
        if (returnStatement) {
          const expression = returnStatement.getExpression();
          sourceFile.addStatements(`return ${expression.getText()};`);
          returnStatement.remove();
        }
      }
    
      return sourceFile.getFullText();
    }
  • Prompt template assigned to the 'code' input schema's description, providing detailed instructions for generating valid AWS SDK V2 JavaScript code.
    const codePrompt = `Your job is to answer questions about AWS environment by writing Javascript code using AWS SDK V2. The code must be adhering to a few rules:
    - Must be preferring promises over callbacks
    - Think step-by-step before writing the code, approach it logically
    - MUST written in Javascript (NodeJS) using AWS-SDK V2
    - Avoid hardcoded values like ARNs
    - Code written should be as parallel as possible enabling the fastest and the most optimal execution
    - Code should be handling errors gracefully, especially when doing multiple SDK calls (e.g. when mapping over an array). Each error should be handled and logged with a reason, script should continue to run despite errors
    - DO NOT require or import "aws-sdk", it is already available as "AWS" variable
    - Access to 3rd party libraries apart from "aws-sdk" is not allowed or possible
    - For base64 encoding, use btoa() function instead of Buffer (Buffer is not available in this environment)
    - Data returned from AWS-SDK must be returned as JSON containing only the minimal amount of data that is needed to answer the question. All extra data must be filtered out
    - Code MUST "return" a value: string, number, boolean or JSON object. If code does not return anything, it will be considered as FAILED
    - Whenever tool/function call fails, retry it 3 times before giving up with an improved version of the code based on the returned feedback
    - When listing resources, ensure pagination is handled correctly so that all resources are returned
    - Do not include any comments in the code
    - When doing reduce, don't forget to provide an initial value
    - Try to write code that returns as few data as possible to answer without any additional processing required after the code is run
    - This tool can ONLY write code that interacts with AWS. It CANNOT generate charts, tables, graphs, etc. Please use artifacts for that instead
    Be concise, professional and to the point. Do not give generic advice, always reply with detailed & contextual data sourced from the current AWS environment. Assume user always wants to proceed, do not ask for confirmation. I'll tip you $200 if you do this right.`;
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 offers minimal information. 'Run AWS code' doesn't reveal whether this is a read or write operation, what permissions are required, whether it has side effects, or what happens on failure. The extensive rules in the schema's code parameter description are implementation requirements rather than behavioral characteristics of the tool itself.

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 extremely concise at just three words, with zero wasted space. It's front-loaded with the essential information (though that information is inadequate). There are no unnecessary sentences or redundant phrasing to critique from a conciseness perspective.

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 tool with 4 parameters, no annotations, and no output schema, the description is completely inadequate. It doesn't explain what the tool does, when to use it, what behaviors to expect, or what results it produces. The extensive rules in the schema's code parameter description don't compensate for the missing contextual information about the tool's purpose and operation.

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

Parameters3/5

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

The description adds no parameter semantics beyond what's already in the schema, which has 100% coverage with detailed descriptions for all four parameters. The baseline score of 3 reflects that the schema does the heavy lifting, though the tool description itself contributes nothing additional about parameter meaning or usage.

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 'Run AWS code' is a tautology that merely restates the tool name without specifying what the tool actually does. It doesn't explain that this tool executes JavaScript code against AWS environments using the AWS SDK, nor does it differentiate from sibling tools like list-credentials or select-profile. The description fails to provide a clear verb+resource combination that would help an agent understand the tool's function.

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 no guidance on when to use this tool versus alternatives. There's no mention of prerequisites, appropriate contexts, or exclusions. While the input schema's code parameter description contains extensive implementation rules, these are technical constraints rather than usage guidelines for an AI agent deciding when to invoke this tool versus other AWS-related tools.

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

Related 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/RafalWilinski/aws-mcp'

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