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

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮