Skip to content

Commit 90cc7cf

Browse files
authored
GODRIVER-2368 Add example for AWS Lambda handler. (#1096)
Add example for AWS Lambda handler.
1 parent acfd7a3 commit 90cc7cf

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (C) MongoDB, Inc. 2022-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
package examples
8+
9+
import (
10+
"context"
11+
"os"
12+
13+
runtime "github.com/aws/aws-lambda-go/lambda"
14+
"go.mongodb.org/mongo-driver/mongo"
15+
"go.mongodb.org/mongo-driver/mongo/options"
16+
)
17+
18+
// Start AWS Lambda Example 1
19+
20+
var client, err = mongo.Connect(context.TODO(), options.Client().ApplyURI(os.Getenv("MONGODB_URI")))
21+
22+
func HandleRequest(ctx context.Context) error {
23+
if err != nil {
24+
return err
25+
}
26+
return client.Ping(context.TODO(), nil)
27+
}
28+
29+
// End AWS Lambda Example 1
30+
31+
func main() {
32+
runtime.Start(HandleRequest)
33+
}

0 commit comments

Comments
 (0)