Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Basic JavaScript Runner #2

Open
Open
@metaskills

Description

Here is a simple handler I cooked up in a node project.

import env from "./env.js";
env.rollbar;
import { execSync } from "child_process";
export const handler = async (event) => {
 const cwd = process.env.LAMBDA_TASK_ROOT || process.cwd();
 const command = event?.X_LAMBDA_CONSOLE?.run;
 if (command) {
 try {
 const options = {
 cwd,
 env: process.env,
 stdio: ["ignore", "pipe", "pipe"], // stdin, stdout, stderr
 encoding: "utf-8",
 };
 const stdout = execSync(command, options);
 return { statusCode: 0, headers: {}, body: stdout };
 } catch (error) {
 const stderr = error.stderr.toString();
 return { statusCode: 1, headers: {}, body: error.stderr.toString() };
 }
 } else {
 return {
 statusCode: 1,
 headers: {},
 body: `Command not found\n`,
 };
 }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /