Skip to content

Commit f290290

Browse files
authored
PYTHON-3097 Language specific examples for AWS Lambda (#984)
1 parent ae71872 commit f290290

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/auth_aws/test_auth_aws.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,37 @@ def test_connect_uri(self):
5454
client.get_database().test.find_one()
5555

5656

57+
class TestAWSLambdaExamples(unittest.TestCase):
58+
def test_shared_client(self):
59+
# Start AWS Lambda Example 1
60+
import os
61+
62+
from pymongo import MongoClient
63+
64+
client = MongoClient(host=os.environ["MONGODB_URI"])
65+
66+
def lambda_handler(event, context):
67+
return client.db.command("ping")
68+
69+
# End AWS Lambda Example 1
70+
71+
def test_IAM_auth(self):
72+
# Start AWS Lambda Example 2
73+
import os
74+
75+
from pymongo import MongoClient
76+
77+
client = MongoClient(
78+
host=os.environ["MONGODB_URI"],
79+
authSource="$external",
80+
authMechanism="MONGODB-AWS",
81+
)
82+
83+
def lambda_handler(event, context):
84+
return client.db.command("ping")
85+
86+
# End AWS Lambda Example 2
87+
88+
5789
if __name__ == "__main__":
5890
unittest.main()

0 commit comments

Comments
 (0)