@@ -128,14 +128,14 @@ in the following sample code.
128
128
---------------
129
129
130
130
.. note::
131
- The MONGODB-AWS authentication mechanism is only available in MongoDB
131
+ The MONGODB-AWS authentication mechanism is available only in MongoDB
132
132
versions 4.4 and later.
133
133
134
134
The ``MONGODB-AWS`` authentication mechanism uses your Amazon Web Services
135
135
Identity and Access Management (AWS IAM) credentials to authenticate your
136
136
user. If you do not already have the `AWS signature library
137
- <https://www.npmjs.com/package/aws4>`__, install it using the following
138
- ``npm`` command:
137
+ <https://www.npmjs.com/package/aws4>`__, use the following
138
+ ``npm`` command to install it :
139
139
140
140
.. code-block:: bash
141
141
@@ -147,9 +147,10 @@ enabled, specify the ``MONGODB-AWS`` authentication mechanism.
147
147
The driver checks for your credentials in the following sources in order:
148
148
149
149
1. Connection string
150
- 2. Environment variables
151
- 3. AWS ECS endpoint specified in ``AWS_CONTAINER_CREDENTIALS_RELATIVE_URI``
152
- 4. AWS EC2 endpoint. For more information, see `IAM Roles for Tasks
150
+ #. Environment variables
151
+ #. Web identity token file
152
+ #. AWS ECS endpoint specified in ``AWS_CONTAINER_CREDENTIALS_RELATIVE_URI``
153
+ #. AWS EC2 endpoint. For more information, see `IAM Roles for Tasks
153
154
<https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html>`_.
154
155
155
156
.. important::
@@ -161,27 +162,6 @@ The driver checks for your credentials in the following sources in order:
161
162
162
163
.. tabs::
163
164
164
- .. tab:: Environment Variables
165
- :tabid: environment variables
166
-
167
- To authenticate to your MongoDB instance using AWS credentials stored in
168
- environment variables, you must specify the following items:
169
-
170
- - In your connection string, specify the ``MONGODB-AWS`` authentication
171
- mechanism as the value of the ``authMechanism`` parameter.
172
- - In your ``AWS_ACCESS_KEY_ID`` environment variable, specify the value
173
- of your AWS access key ID.
174
- - In your ``AWS_SECRET_ACCESS_KEY`` environment variable, specify the
175
- value of your AWS secret access key.
176
- - If your login requires an AWS session token, specify the value in
177
- your ``AWS_SESSION_TOKEN`` environment variable.
178
-
179
- The following code shows an example of specifying the ``MONGODB-AWS``
180
- authentication mechanism with environment variables:
181
-
182
- .. literalinclude:: /code-snippets/authentication/aws-env-variable.js
183
- :language: javascript
184
-
185
165
.. tab:: Connection String
186
166
:tabid: connection string
187
167
@@ -201,6 +181,49 @@ The driver checks for your credentials in the following sources in order:
201
181
.. literalinclude:: /code-snippets/authentication/aws.js
202
182
:language: javascript
203
183
184
+ .. tab:: Environment Variables
185
+ :tabid: environment variables
186
+
187
+ To authenticate to your MongoDB instance using AWS credentials stored in
188
+ environment variables, set the following variables by using
189
+ a shell:
190
+
191
+ .. code-block:: bash
192
+
193
+ export AWS_ACCESS_KEY_ID=<awsKeyId>
194
+ export AWS_SECRET_ACCESS_KEY=<awsSecretKey>
195
+ export AWS_SESSION_TOKEN=<awsSessionToken>
196
+
197
+ .. note::
198
+
199
+ Omit the line containing ``AWS_SESSION_TOKEN`` if you don't need an AWS
200
+ session token for that role.
201
+
202
+ After you've set the preceding environment variables, specify the ``MONGODB-AWS``
203
+ authentication mechanism in your connection string as shown in the following example:
204
+
205
+ .. literalinclude:: /code-snippets/authentication/aws-env-variable.js
206
+ :language: javascript
207
+
208
+ .. tab:: Web Identity Token File
209
+ :tabid: web-identity-token-file
210
+
211
+ You can use the OpenID Connect (OIDC) token obtained from a web identity provider to authenticate
212
+ to Amazon Elastic Kubernetes Service (EKS) or other services.
213
+ To use an OIDC token, create a file that contains your token, then
214
+ set the absolute path to this file in an environment variable by using
215
+ a shell as shown in the following example:
216
+
217
+ .. code-block:: bash
218
+
219
+ export AWS_WEB_IDENTITY_TOKEN_FILE=<absolute path to file containing your OIDC token>
220
+
221
+ After you've set the preceding environment variable, specify the ``MONGODB-AWS``
222
+ authentication mechanism in your connection string as shown in the following example:
223
+
224
+ .. literalinclude:: /code-snippets/authentication/aws-env-variable.js
225
+ :language: javascript
226
+
204
227
``X.509``
205
228
---------
206
229
0 commit comments