1

I want to use executable file within AWS lambda handler function. Here is my handler function where I want to use executable

func handler(){
    cmd := exec.Command("./balance", "GetBalance", id)
    cmd.Dir = "/Users/xxxx/go/src/getBalance"
    output, err := cmd.Output()
}

I want to use the output of the above command in this handler. Is it possible to use? If possible, do I need to zip both executables? Or is there any other way where I can use executable within the handler?

1 Answer 1

2

Sadly, you will not be able to write to /Users/xxxx/go/src/getBalance. In lambda, you have access only to /tmp.

Also, if you bundle the balance file with your deployment package it will be stored in /var/task alongside your function code.

EDIT:

Based on the new comments, to complete solution also required removal of cmd.Dir and recompilation of balance for linux.

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

5 Comments

So if I bundle balance with my deployment package, it will be stored in /var/task? So do i need to use /var/task instead of /Users/xxxx/go/src/getBalance or do i need to do any modification to my exec.Command?
@Sharath It will be in /var/task/. I don't know if your current command is correct or not. I don't know what is ./balance. It may require some dependencies to run not available in lambda. You have to just try and see how it goes. Only you know what ./balance is, whether it requires any arguments, external libraries, files.
./balance requires two arguments. It will be like ./balance GetBalance 12345 where 12345 is id which is variable. It will give balance of id. It doesn't require any dependencies. I compiled it into linux environment. it is working fine with my other binary. But I don't know how to do with lambda. I will try using /var/task.
Thank you. I found out that I don't need to add any path if I bundle both the binaries together. I just use exec.Command without cmd.Dir. One more thing I was doing wrong before is that I didn't compile balance to linux environment. Now I compiled into linux and not using cmd.Dir. Now it is working.
@Sharath Thanks for letting me know. I can add the extra info to the answer :-)

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.