Skip to content

Local testing example #149

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

Merged
merged 4 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Serverless Framework handles everything from creating namespaces to function/cod
- [Events](#events)
- [Custom domains](#custom-domains)
- [Deployment methods](#deployment-methods)
- [Local testing](#local-testing)
- [Managing containers](#managing-containers)
- [Logs](#logs)
- [Offline testing](#offline-testing)
Expand Down Expand Up @@ -435,6 +436,14 @@ This can be controlled using the `singleSource` option. By default its value is

If `singleSource` is set to `true`, functions and containers not defined in your serverless configuration file will be removed the next time you run the `serverless deploy` command.

### Local testing

`serverless invoke local` is **not supported** directly but instead we provide additional packages to install close to your handler.

Documentation is available through runtimes frameworks for :
* [Go](https://github.com/scaleway/serverless-functions-go)
* [Python](https://github.com/scaleway/serverless-functions-python)

### Managing containers

>**Requirements:**
Expand Down
5 changes: 5 additions & 0 deletions examples/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ The `handler name` must be composed of the folder name and the handler function
If your code depends on private dependencies, you will need to run `go mod vendor` before deploying your function.

See [Official Go Vendoring reference](https://go.dev/ref/mod#go-mod-vendor).

## Local testing

This examples use the [Go Framework](https://github.com/scaleway/serverless-functions-go) for local testing.
To call you handler locally run `go run cmd/main.go`.
12 changes: 12 additions & 0 deletions examples/go/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
scw "myhandler"

"github.com/scaleway/serverless-functions-go/local"
)

func main() {
// Replace "Handle" with your function handler name if necessary
local.ServeHandler(scw.Handle, local.WithPort(8080))
}
4 changes: 4 additions & 0 deletions examples/go/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module myhandler

go 1.18

require github.com/scaleway/serverless-functions-go v0.1.0

require github.com/google/uuid v1.3.0 // indirect
8 changes: 8 additions & 0 deletions examples/go/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/scaleway/serverless-functions-go v0.1.0 h1:U967AmTujugxzzvLIWUNoB+/5hLmsys0Xe7n4L38XPA=
github.com/scaleway/serverless-functions-go v0.1.0/go.mod h1:SKb5XA5bONwJkecQElrKLYOVrg/5kmcaduB440HQbIg=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
7 changes: 7 additions & 0 deletions examples/python3/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ def handle(event, context):
"Content-Type": ["text/plain"],
}
}

# run 'pip install scaleway_functions_python' if necessary
if __name__ == "__main__":
# The import is conditional so that you do not need
# to package the library when deploying on Scaleway Functions.
from scaleway_functions_python import local
local.serve_handler(handle, port=8080)