forked from mongodb/node-mongodb-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaws_handler.js
More file actions
22 lines (19 loc) · 737 Bytes
/
aws_handler.js
File metadata and controls
22 lines (19 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// begin lambda connection
const { MongoClient } = require('mongodb');
const process = require('node:process');
// Get the URI for the cluster and use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
// from the environment, then set the appropriate auth options. Note that MongoClient
// now auto-connects so no need to store the connect() promise anywhere and reference it.
const client = new MongoClient(process.env.MONGODB_URI, {
authSource: '$external',
authMechanism: 'MONGODB-AWS'
});
module.exports.handler = async function () {
const databases = await client.db('admin').command({ listDatabases: 1 });
return {
statusCode: 200,
databases: databases
};
};
// end lambda connection
module.exports.client = client;