Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to deploy lambda function written in Go

I am attempting to deploy my code to AWS Lambda. I've written it in Go. It builds just fine but I receive this error when running it via the Lambda test functionality:

{
  "errorMessage": "fork/exec /var/task/github-activity: no such file or directory",
  "errorType": "PathError"
}

You can view the full code at: https://github.com/JustinDFuller/github-activity I have tested and seen that it works fine on my machine. (I've tried on windows and linux).

The file I am deploying is made by running the following commands:

GOOS=linux GOARCH=amd64 go build -o main awsLambdaImpl.go zip main.zip main

like image 596
Justin Avatar asked Mar 03 '18 01:03

Justin


People also ask

Is Golang good for AWS Lambda?

With all this in mind, you can rest assured that Go is an excellent choice for AWS Lambda: A performant, cost-efficient language with the bonus of being able to run the latest (or even prerelease) version of the Go language without waiting for AWS to update their runtimes.

Does Golang have Lambda?

So does golang have lambda functions, YES golang have function literals that serve the same functionality as lambda expressions. These function literals are anonymous functions that do not have a name and can be defined inline i.e inside of other functions.

Why is my Lambda function taking so long?

Lambda: Execution takes too long If your code takes much longer to run in Lambda than on your local machine, it may be constrained by the memory or processing power available to the function. Configure the function with additional memory to increase both memory and CPU.


1 Answers

Handler for a Go Lambda is the path to executable.

Since you're uploading a zip file of the following structure

main.zip
|
`-- main  <-- executable

your handler name has to be main.

If you packed your lambda in the following way, your handler would then be

main.zip
|
`-- subdir
      |
      `-- executableInASubdirPackedIntoAZip  <-- executable

your handler would then be subdir/executableInASubdirPackedIntoAZip.

like image 99
mewa Avatar answered Oct 02 '22 13:10

mewa