Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.
46 changes: 43 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,53 @@ curl http://node43-test.default.dev.triggermesh.io
{"statusCode":200,"headers":{"Content-Type":"text/html"},"body":"\n <html>\n <style>\n h1 { color: #73757d; }\n </style>\n <body>\n <h1>Landing Page</h1>\n <p>Hey Unknown!</p>\n </body>\n </html>"}
```

### Node 10 with `asnc` handler

1. Prepare function code

```
mkdir example-lambda-nodejs
cd example-lambda-nodejs
cat > handler.js <<EOF
async function justWait() {
return new Promise((resolve, reject) => setTimeout(resolve, 100));
}

module.exports.sayHelloAsync = async (event) => {
await justWait();
return {hello: event.name};
};
EOF

node -e "require('./handler').sayHelloAsync({}).then(h => console.log(h))"
```

2. Install node-10.x buildtemplate

```
tm deploy buildtemplate -f https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/node-10.x/buildtemplate.yaml
```

3. Deploy function

```
tm deploy service node-lambda -f . --build-template knative-node10-runtime --build-argument HANDLER=handler.sayHelloAsync --wait
```

Done:

```
curl http://node-lambda.default.dev.triggermesh.io --data '{"name": "Foo"}'
# {"hello":"Foo"}
```

### Go

1. Prepare function code

```
mkdir lambda
cd lambda
mkdir example-lambda-go
cd example-lambda-go
cat > main.go <<EOF
package main

Expand All @@ -73,7 +113,7 @@ import (
)

type MyEvent struct {
Name string `json:"name"`
Name string \`json:"name"\`
}

func HandleRequest(ctx context.Context, name MyEvent) (string, error) {
Expand Down