@@ -133,35 +133,67 @@ in the following sample code.
133133
134134The ``MONGODB-AWS`` authentication mechanism uses your Amazon Web Services
135135Identity and Access Management (AWS IAM) credentials to authenticate your
136- user.
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:
139+
140+ .. code-block:: bash
141+
142+ npm install aws4
137143
138144To connect to a MongoDB instance with ``MONGODB-AWS`` authentication
139- enabled, specify the ``MONGODB-AWS`` authentication mechanism and pass
140- your ``AWS_ACCESS_KEY_ID`` and ``AWS_SECRET_ACCESS_KEY`` credentials to the
141- driver when you attempt to connect. If your AWS login requires a session
142- token, you must include your ``AWS_SESSION_TOKEN`` as well.
145+ enabled, specify the ``MONGODB-AWS`` authentication mechanism.
143146
144- The driver checks the following sources for your credentials in order:
147+ The driver checks for your credentials in the following sources in order:
145148
1461491. Connection string
1471502. Environment variables
1481513. AWS ECS endpoint specified in ``AWS_CONTAINER_CREDENTIALS_RELATIVE_URI``
1491524. AWS EC2 endpoint. For more information, see `IAM Roles for Tasks
150153 <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html>`_.
151154
152- If you do not already have the `AWS signature library <https://www.npmjs.com/package/aws4>`__,
153- install it using the following ``npm`` command:
155+ .. tabs::
154156
155- .. code-block:: console
157+ .. tab:: Environment Variables
158+ :tabid: environment variables
156159
157- npm install aws4
160+ To connect to your MongoDB instance with environment variables,
161+ add your ``AWS_ACCESS_KEY_ID`` and ``AWS_SECRET_ACCESS_KEY``
162+ credentials to your environment variables. If your AWS
163+ login requires an ``AWS_SESSION_TOKEN``, add it to your
164+ environment variables as well.
158165
159- The following code shows an example of specifying the ``MONGODB-AWS``
160- authentication mechanism and credentials in the connection string :
166+ The following code shows an example of specifying the ``MONGODB-AWS``
167+ authentication mechanism with environment variables :
161168
162- .. literalinclude:: /code-snippets/authentication/aws.js
163- :language: javascript
169+ .. note::
170+
171+ You don't need to specify these credentials in your connection URI
172+ because the driver automatically retrieves them when you attempt
173+ to connect.
174+
175+ .. literalinclude:: /code-snippets/authentication/aws-env-variable.js
176+ :language: javascript
177+
178+ .. tab:: Connection String
179+ :tabid: connection string
180+
181+ To connect to your MongoDB instance with a connection string, pass
182+ your ``AWS_ACCESS_KEY_ID`` and ``AWS_SECRET_ACCESS_KEY``
183+ credentials to the driver when you attempt to connect. If your AWS
184+ login requires a session token, include your ``AWS_SESSION_TOKEN`` as well.
185+
186+ The following code shows an example of specifying the ``MONGODB-AWS``
187+ authentication mechanism and credentials with a connection string:
188+
189+ .. important::
190+
191+ Always **URI encode** the username and certificate file path using the
192+ ``encodeURIComponent`` method to ensure they are correctly parsed.
164193
194+ .. literalinclude:: /code-snippets/authentication/aws.js
195+ :language: javascript
196+
165197``X.509``
166198---------
167199
0 commit comments