Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golang support #4507

Closed
RafalWilinski opened this issue Nov 30, 2017 · 13 comments
Closed

Golang support #4507

RafalWilinski opened this issue Nov 30, 2017 · 13 comments
Assignees
Milestone

Comments

@RafalWilinski
Copy link
Contributor

This is a Feature Proposal

Description

AWS Lambda now supports Golang: https://twitter.com/mthenw/status/936302935478358016
We should add aws-golang template.

@horike37
Copy link
Member

horike37 commented Dec 1, 2017

It was pre-announcement at re-invent. We should wait for the official release a couple of weeks.

@horike37
Copy link
Member

horike37 commented Jan 16, 2018

Finally!
https://aws.amazon.com/about-aws/whats-new/2018/01/aws-lambda-supports-go/

@mrserverless
Copy link

I can spend some time looking at this and potentially consolidate of the things I've been doing in https://github.com/yunspace/serverless-golang into the official repo. Happy to collaborate on this if anyone has already started

@horike37
Copy link
Member

AWESOME @yunspace 💯 Thank you for jumping in !!!
I know your plugin 😄 That is one of the most popular plugins of the framework!

AFAIK, nobody started working on this, so it would be great if you can do that 😄
To introduce this new feature, we need to implement the following stuff.

  1. Specify golang runtime to CloudFormation template generated by the framework.
  2. Add golang template when running sls create --template aws-golang.
  3. Add test template with docker-compose.
  4. Add it to the framework documentation.

Additionally, we need local invoke functionality as well, but it would be good to separate another issue.

You can refer to the past PR for introducing other templates something like this
#3483
#3849

Let us (@serverless/framework-maintainers) know if you have any other questions!

@flemay
Copy link

flemay commented Jan 16, 2018

Looking at the documentation Lambda Handler in Go , it seems the handler.go would only be for 1 lambda (1 main() function to start the lambda) so I was wondering how would Serverless use the same code for more than 1 function. 🤔

@HyperBrain
Copy link
Member

@flemay Opposed to other languages, Go exports a main() function as entry point for the executable - so it should be one executable per handler, which is perfectly fine.
I see code sharing here on a Go library level. If you want to share code, create multiple libraries and import them into your handlers.

@franciscocpg
Copy link
Contributor

franciscocpg commented Jan 16, 2018

right @HyperBrain 👍
But in this case this (one executable per handler) also means that we need one folder per handler.

What I mean is:

this should not work

.
├── handler1.go
├── handler2.go

this should work

.
├── handler1
│   └── main.go
├── handler2
│   └── main.go

@HyperBrain
Copy link
Member

@franciscocpg That should be easy to achieve. If the runtime is "go", it should be disallowed to specify handlers without a relative path in the serverless.yml.

# serverless.yml
functions:
  okfunc:
    handler: myfunc/handler
  invalidfunc:
    handler: handler

Does that sound feasible?

@flemay
Copy link

flemay commented Jan 16, 2018

So I've tried with 1 function only with different approaches: in folder, not in folder
Also tried with handler executable matching the name of the function generated by serverless i.e myproject-stage-functionname because according to AWS doc

Note that your function-name must match the name of your Lambda handler name

And I've got errors similar to the following

{
    "errorMessage": "fork/exec /var/task/myproject-dev-handler: no such file or directory",
    "errorType": "PathError"
}

Somehow it does not find anything in /var/task 🤔

@flemay
Copy link

flemay commented Jan 18, 2018

I got it working! Thanks to this serverless blog

@joekr
Copy link

joekr commented Jan 18, 2018

In order to get serverless create -u https://github.com/serverless/serverless-golang/ -p myservice to work from the blog post I had to do a few things first:

  1. run npm install -g serverless to upgrade to serverless@1.25.0
  2. run go get github.com/aws/aws-lambda-go/lambda before running GOOS=linux go build -o bin/main

Thought this might help some others out.

@mrserverless
Copy link

thanks @flemay for the good find. Following @mthenw's template makes things a lot easier. I should be able to get a draft PR in by end of the day.

@mrserverless mrserverless mentioned this issue Jan 19, 2018
7 tasks
@mrserverless
Copy link

smashed out PR #4669 on a 4 hour bus ride to Canberra... should be ready soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants