4

I have written a lambda function that executes another exe file named abc.exe.

Now I have created a zip of lambda function and uploaded it to aws. I am not sure where to put my "abc.exe"

I tried putting it in the same zip but I get below error:

exec: "abc": executable file not found in $PATH:

Here is my lambda function code:

func HandleLambdaEvent(request Request) (Response, error) {

    fmt.Println("Input", request.Input)
    fmt.Println("Output", request.Output)

    cmd := exec.Command("abc", "-v", "--lambda", request.Input, "--out", request.Output)
    var out bytes.Buffer
    var stderr bytes.Buffer
    cmd.Stdout = &out
    cmd.Stderr = &stderr
    err := cmd.Run()

    if err != nil {
        fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
        return Response{Message: fmt.Sprintf(stderr.String())}, nil
    }
    fmt.Println("Result: " + out.String())

    return Response{Message: fmt.Sprintf(" %s and %s are input and output", request.Input, request.Output)}, nil
}

Update:

Trial 1:

I uploaded abc.exe to s3 then in my HandleLambdaEvent function I am downloading it to tmp/ folder. And next when i try to access it after successful download, it shows below error:

fork/exec /tmp/abc: no such file or directory:

Code to download abc.exe :

file, err2 := os.Create("tmp/abc.exe")
    if err2 != nil {
        fmt.Println("Unable to create file %q, %v", err2)
    }

    defer file.Close()


    sess, _ := session.NewSession(&aws.Config{
        Region: aws.String(region)},
    )

    downloader := s3manager.NewDownloader(sess)

    numBytes, err2 := downloader.Download(file,
        &s3.GetObjectInput{
            Bucket: aws.String(bucket),
            Key:    aws.String("abc.exe"),
        })
    if err2 != nil {
        fmt.Println("Unable to download item %q, %v", fileName, err2)
    }

    fmt.Println("Downloaded", file.Name(), numBytes, "bytes")
    file.Close()
6
  • I know next to nothing about Lambda, but are you sure you even can execute an external binary? That seems counter-intuitive to me, like it violates the point of Lambda. Commented Mar 16, 2019 at 10:20
  • What sort of file is the .exe file? Is it a Windows app? Commented Mar 16, 2019 at 10:31
  • @Flimzy i am not sure either. It's trial and error for me as well. But to check whether lambda can execute binary, firstly I need a way to access it from lambda :) Commented Mar 16, 2019 at 11:28
  • 1
    I wonder if you can just use GO directly? Announcing Go Support for AWS Lambda | AWS Compute Blog and Building Lambda Functions with Go - AWS Lambda Commented Mar 16, 2019 at 21:46
  • 4
    I doubt that you are going in the correct direction, overall, but the immediate problem is that .exe is never implied in Linux. The full filename, e.g. exec.Command("abc.exe", ... would be required. Commented Mar 16, 2019 at 21:49

1 Answer 1

3

are you sure you even can execute an external binary? That seems counter-intuitive to me, like it violates the point of Lambda

Perfectly acceptable. Have a look at Running Arbitrary Executables in AWS Lambda on the AWS Compute Blog.

I am not sure where to put my "abc.exe"

To run executables on Lambda package them in the ZIP file you upload. Then do something like

exec.Command(path.Join(os.GetEnv("LAMBDA_TASK_ROOT"), "abc.exe"))

What sort of file is the .exe file? Is it a Windows app?

You won't be able to run Windows apps on Lambda. The linked blog post says: If you compile your own binaries, ensure that they’re either statically linked or built for the matching version of Amazon Linux

Sign up to request clarification or add additional context in comments.

2 Comments

Environment Variables Available to Lambda Functions docs.aws.amazon.com/lambda/latest/dg/…
How would you run the executable with commandline arguments? I am doing a similar thing in python, and am able to run the executable via subprocess.Popen(args) where args = "./abc.exe". Would I just add another element to the list of args?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.