Skip to content

Commit c546f24

Browse files
committed
Fix
1 parent cf46f7b commit c546f24

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
// start-custom-credentials
2-
const { MongoClient } = require('mongodb');
3-
const { fromNodeProviderChain } = require('@aws-sdk/credential-providers');
1+
{
2+
// start-custom-credentials
3+
const { MongoClient } = require('mongodb');
4+
const { fromNodeProviderChain } = require('@aws-sdk/credential-providers');
45

5-
const client = new MongoClient('<cluster_url>?authMechanism=MONGODB-AWS', {
6-
authMechanismProperties: {
7-
AWS_CREDENTIAL_PROVIDER: fromNodeProviderChain()
8-
}
9-
});
10-
// end-custom-credentials
6+
const client = new MongoClient('<cluster_url>?authMechanism=MONGODB-AWS', {
7+
authMechanismProperties: {
8+
AWS_CREDENTIAL_PROVIDER: fromNodeProviderChain()
9+
}
10+
});
11+
// end-custom-credentials
12+
}
1113

14+
{
1215
// start-custom-credentials-function
13-
const { MongoClient } = require('mongodb');
16+
const { MongoClient } = require('mongodb');
1417

15-
const client = new MongoClient('<cluster_url>?authMechanism=MONGODB-AWS', {
16-
authMechanismProperties: {
17-
AWS_CREDENTIAL_PROVIDER: async () => {
18-
return {
19-
accessKeyId: process.env.ACCESS_KEY_ID,
20-
secretAccessKey: process.env.SECRET_ACCESS_KEY
18+
const client = new MongoClient('<cluster_url>?authMechanism=MONGODB-AWS', {
19+
authMechanismProperties: {
20+
AWS_CREDENTIAL_PROVIDER: async () => {
21+
return {
22+
accessKeyId: process.env.ACCESS_KEY_ID,
23+
secretAccessKey: process.env.SECRET_ACCESS_KEY
24+
}
2125
}
2226
}
23-
}
24-
});
25-
// end-custom-credentials-function
27+
});
28+
// end-custom-credentials-function
29+
}

source/security/authentication/aws-iam.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ from the AWS SDK to the AWS authentication mechanism:
167167
.. literalinclude:: /code-snippets/authentication/aws-custom-credentials.js
168168
:language: javascript
169169
:start-after: // start-custom-credentials
170-
:end-before: // end-custom-credentials
170+
:end-before: // end-custom-credentials
171+
:dedent:
171172

172173
To use a custom provider, you can pass any asynchronous function that returns your credentials
173174
to the ``AWS_CREDENTIAL_PROVIDER`` property. The following example shows how to pass
@@ -178,6 +179,7 @@ AWS authentication mechanism:
178179
:language: javascript
179180
:start-after: // start-custom-credentials-function
180181
:end-before: // end-custom-credentials-function
182+
:dedent:
181183

182184
API Documentation
183185
-----------------

0 commit comments

Comments
 (0)