Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit 44e1ab9

Browse files
authored
Merge pull request #10 from solsson/node10-example
Document a Node 10.x example
2 parents 6f08d1c + fe210b1 commit 44e1ab9

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

README.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,53 @@ curl http://node43-test.default.dev.triggermesh.io
5656
{"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>"}
5757
```
5858

59+
### Node 10 with `asnc` handler
60+
61+
1. Prepare function code
62+
63+
```
64+
mkdir example-lambda-nodejs
65+
cd example-lambda-nodejs
66+
cat > handler.js <<EOF
67+
async function justWait() {
68+
return new Promise((resolve, reject) => setTimeout(resolve, 100));
69+
}
70+
71+
module.exports.sayHelloAsync = async (event) => {
72+
await justWait();
73+
return {hello: event.name};
74+
};
75+
EOF
76+
77+
node -e "require('./handler').sayHelloAsync({}).then(h => console.log(h))"
78+
```
79+
80+
2. Install node-10.x buildtemplate
81+
82+
```
83+
tm deploy buildtemplate -f https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/node-10.x/buildtemplate.yaml
84+
```
85+
86+
3. Deploy function
87+
88+
```
89+
tm deploy service node-lambda -f . --build-template knative-node10-runtime --build-argument HANDLER=handler.sayHelloAsync --wait
90+
```
91+
92+
Done:
93+
94+
```
95+
curl http://node-lambda.default.dev.triggermesh.io --data '{"name": "Foo"}'
96+
# {"hello":"Foo"}
97+
```
98+
5999
### Go
60100

61101
1. Prepare function code
62102

63103
```
64-
mkdir lambda
65-
cd lambda
104+
mkdir example-lambda-go
105+
cd example-lambda-go
66106
cat > main.go <<EOF
67107
package main
68108
@@ -73,7 +113,7 @@ import (
73113
)
74114
75115
type MyEvent struct {
76-
Name string `json:"name"`
116+
Name string \`json:"name"\`
77117
}
78118
79119
func HandleRequest(ctx context.Context, name MyEvent) (string, error) {

0 commit comments

Comments
 (0)