Make sure serverless
is installed. See installation guide.
You should also have go and make
It is always good practice to organise your go
projects within GOPATH, to maximise the benefits of go tooling.
There are two templates for go
:
- aws-go -
serverless create --template aws-go --path myService
- aws-go-dep -
serverless create --template aws-go-dep --path myService
where:
- 'aws-go' fetches dependencies using standard
go get
. - 'aws-go-dep' uses go dep and requires your project to be in
$GOPATH/src
- 'myService' is a new folder to be created with template service files.
Change directories into 'myService' folder and you can see this project has 2 handler functions: hello
and world
split into 2 separate go packages (folders):
.
├── hello/
│ └── main.go
├── world/
│ └── main.go
This because a main()
function is required as entry point for each handler executable.
Run make build
to build both functions. Successful build should generate the following binaries:
.
├── bin/
│ |── hello
│ └── world
serverless deploy
or sls deploy
. sls
is shorthand for the Serverless CLI command
Invoking the both functions should return a successful results:
serverless invoke -f hello
{
"message": "Go Serverless v1.0! Your function executed successfully!"
}
serverless invoke --f world
{
"message": "Okay so your other function also executed successfully!"
}
Congrats you have just deployed and run your Hello World function!