Skip to content

Commit dae35c2

Browse files
authored
DOCSP:13409 aws session token auth (#213)
* DOCSP-13409: added aws session token connection instructions
1 parent cf1432a commit dae35c2

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

source/code-snippets/authentication/aws.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@ const clusterUrl = "<MongoDB cluster url>";
77

88
const authMechanism = "MONGODB-AWS";
99

10-
// Replace the following with your MongoDB deployment's connection string.
11-
const uri =
10+
let uri =
1211
`mongodb+srv://${accessKeyId}:${secretAccessKey}@${clusterUrl}/?authMechanism=${authMechanism}`;
1312

14-
// Create a new MongoClient
13+
// Uncomment the following lines if your AWS authentication setup requires a session token.
14+
// const sessionToken = encodeURIComponent("<AWS_SESSION_TOKEN>");
15+
// uri = uri.concat(`&authMechanismProperties=${sessionToken}`);
16+
17+
// Create a new MongoClient.
1518
const client = new MongoClient(uri);
1619

17-
// Function to connect to the server
1820
async function run() {
1921
try {
20-
// Connect the client to the server
22+
// Connect the client to the server.
2123
await client.connect();
2224

23-
// Establish and verify connection
25+
// Establish and verify connection.
2426
await client.db("admin").command({ ping: 1 });
25-
console.log("Connected successfully to server");
27+
console.log("Connected successfully to server.");
2628
} finally {
27-
// Ensures that the client will close when you finish/error
29+
// Ensure that the client closes when it finishes/errors.
2830
await client.close();
2931
}
3032
}

source/fundamentals/authentication/mechanisms.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,19 @@ The driver checks the following sources for your credentials in order:
149149
4. AWS EC2 endpoint. For more information, see `IAM Roles for Tasks
150150
<https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html>`_.
151151

152-
If you do not already have the `aws signature library <https://www.npmjs.com/package/aws4>`__,
152+
If you do not already have the `AWS signature library <https://www.npmjs.com/package/aws4>`__,
153153
install it using the following ``npm`` command:
154154

155155
.. code-block:: console
156156

157157
npm install aws4
158158

159159
The following code shows an example of specifying the ``MONGODB-AWS``
160-
authentication mechanism and credentials in the connection string.
160+
authentication mechanism and credentials in the connection string:
161161

162162
.. literalinclude:: /code-snippets/authentication/aws.js
163163
:language: javascript
164164

165-
166165
``X.509``
167166
---------
168167

0 commit comments

Comments
 (0)