dongmei8209 2019-03-16 07:48
浏览 96

如何从AWS Lambda执行exe文件

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()
  • 写回答

1条回答 默认 最新

  • doubi2145 2019-09-11 13:50
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?