@@ -36,12 +36,14 @@ Code Placeholders
3636The code examples on this page use the following placeholders:
3737
3838- ``<hostname>``: The network address of your MongoDB Atlas deployment
39- - ``<awsKeyId >``: Your AWS access key ID
40- - ``<awsSecretKey >``: Your AWS secret access key
41- - ``<awsSessionToken >``: Your AWS session token
39+ - ``<AWS IAM access key ID >``: Your AWS access key ID
40+ - ``<AWS IAM secret access key >``: Your AWS secret access key
41+ - ``<AWS session token >``: Your AWS session token
4242
4343To use the code examples on this page, replace these placeholders with your own values.
4444
45+ .. include:: /includes/authentication/percent-encoding.rst
46+
4547Using AWS IAM Authentication in Your Application
4648------------------------------------------------
4749
@@ -56,7 +58,7 @@ To use AWS IAM authentication, you must install {+driver-short+} with the
5658tries to retrieve AWS credentials from the following sources, in the order listed:
5759
58601. Named arguments passed to the ``MongoClient`` constructor or parameters in the
59- connection URI
61+ connection string
6062#. Environment variables
6163#. Shared credentials file
6264#. AWS config file
@@ -74,13 +76,13 @@ these sources and use them to authenticate your application.
7476
7577First, {+driver-short+} checks whether you passed AWS credentials
7678to the ``MongoClient`` constructor, either as a named argument or as part of the
77- connection URI . To pass your credentials to ``MongoClient``,
79+ connection string . To pass your credentials to ``MongoClient``,
7880set the following connection options:
7981
8082- ``username``: The AWS IAM access key ID to authenticate. Percent-encode this value
81- before including it in a connection URI .
83+ before including it in a connection string .
8284- ``password``: The AWS IAM secret access key. Percent-encode this value before including
83- it in a connection URI .
85+ it in a connection string .
8486- ``authMechanism``: Set to ``"MONGODB-AWS"``.
8587
8688You can set these options in two ways: by passing arguments to the
@@ -93,7 +95,7 @@ You can set these options in two ways: by passing arguments to the
9395
9496 .. code-block:: python
9597
96- client = pymongo.MongoClient("mongodb://@ <hostname>:<port >",
98+ client = pymongo.MongoClient("mongodb+srv ://<hostname>",
9799 username="<AWS IAM access key ID>",
98100 password="<AWS IAM secret access key>",
99101 authMechanism="MONGODB-AWS")
@@ -103,9 +105,9 @@ You can set these options in two ways: by passing arguments to the
103105
104106 .. code-block:: python
105107
106- uri = ("mongodb://<percent-encoded AWS IAM access key ID>:"
108+ uri = ("mongodb+srv ://<percent-encoded AWS IAM access key ID>:"
107109 "<percent-encoded AWS IAM secret access key>"
108- "@<hostname>:<port> /?"
110+ "@<hostname>/?"
109111 "&authMechanism=MONGODB-AWS")
110112 client = pymongo.MongoClient(uri)
111113
@@ -148,15 +150,15 @@ You can set this option in two ways: by passing an argument to the
148150
149151 .. code-block:: python
150152
151- client = pymongo.MongoClient("mongodb://<hostname>:<port >",
153+ client = pymongo.MongoClient("mongodb+srv ://<hostname>",
152154 authMechanism="MONGODB-AWS")
153155
154156 .. tab:: Connection String
155157 :tabid: connectionstring
156158
157159 .. code-block:: python
158160
159- uri = "mongodb://<hostname>:<port >/?&authMechanism=MONGODB-AWS"
161+ uri = "mongodb+srv ://<hostname>/?&authMechanism=MONGODB-AWS"
160162 client = pymongo.MongoClient(uri)
161163
162164.. tip:: AWS Lambda
@@ -194,15 +196,15 @@ You can set this option in two ways: by passing an argument to the
194196
195197 .. code-block:: python
196198
197- client = pymongo.MongoClient("mongodb://<hostname>:<port >",
199+ client = pymongo.MongoClient("mongodb+srv ://<hostname>",
198200 authMechanism="MONGODB-AWS")
199201
200202 .. tab:: Connection String
201203 :tabid: connectionstring
202204
203205 .. code-block:: python
204206
205- uri = "mongodb://<hostname>:<port >/?&authMechanism=MONGODB-AWS"
207+ uri = "mongodb+srv ://<hostname>/?&authMechanism=MONGODB-AWS"
206208 client = pymongo.MongoClient(uri)
207209
208210.. tip::
@@ -244,15 +246,15 @@ You can set this option in two ways: by passing an argument to the
244246
245247 .. code-block:: python
246248
247- client = pymongo.MongoClient("mongodb://<hostname>:<port >",
249+ client = pymongo.MongoClient("mongodb+srv ://<hostname>",
248250 authMechanism="MONGODB-AWS")
249251
250252 .. tab:: Connection String
251253 :tabid: connectionstring
252254
253255 .. code-block:: python
254256
255- uri = "mongodb://<hostname>:<port >/?&authMechanism=MONGODB-AWS"
257+ uri = "mongodb+srv ://<hostname>/?&authMechanism=MONGODB-AWS"
256258 client = pymongo.MongoClient(uri)
257259
258260.. _pymongo-mongodb-aws-assume-role:
@@ -275,11 +277,11 @@ in the AWS documentation.
275277After you create the config file, set the following connection options:
276278
277279- ``username``: The AWS IAM access key ID to authenticate returned by the ``AssumeRole``
278- request. Percent-encode this value before including it in a connection URI .
280+ request. Percent-encode this value before including it in a connection string .
279281- ``password``: The AWS IAM secret access key returned by the ``AssumeRole`` request.
280- Percent-encode this value before including it in a connection URI. .
282+ Percent-encode this value before including it in a connection string .
281283- ``authMechanismProperties``: Set to ``AWS_SESSION_TOKEN:`` and the
282- AWS session token returned by the ``AssumeRole`` request.
284+ AWS session token returned by the ``AssumeRole`` request.
283285- ``authMechanism``: Set to ``"MONGODB-AWS"``.
284286
285287You can set these options in two ways: by passing arguments to the
@@ -294,7 +296,7 @@ You can set these options in two ways: by passing arguments to the
294296
295297 .. code-block:: python
296298
297- client = pymongo.MongoClient("mongodb://@<hostname>:<port >",
299+ client = pymongo.MongoClient("mongodb+srv ://@<hostname>",
298300 username="<AWS IAM access key ID>",
299301 password="<AWS IAM secret access key>",
300302 authMechanismProperties="AWS_SESSION_TOKEN:<AWS session token>",
@@ -305,9 +307,9 @@ You can set these options in two ways: by passing arguments to the
305307
306308 .. code-block:: python
307309
308- uri = ("mongodb://<percent-encoded AWS IAM access key ID>:"
310+ uri = ("mongodb+srv ://<percent-encoded AWS IAM access key ID>:"
309311 "<percent-encoded AWS IAM secret access key>"
310- "@<hostname>:<port> /?"
312+ "@<hostname>/?"
311313 "authMechanismProperties=AWS_SESSION_TOKEN:<AWS session token>"
312314 "&authMechanism=MONGODB-AWS")
313315 client = pymongo.MongoClient(uri)
@@ -353,15 +355,15 @@ You can set this option in two ways: by passing an argument to the
353355
354356 .. code-block:: python
355357
356- client = pymongo.MongoClient("mongodb://<hostname>:<port >",
358+ client = pymongo.MongoClient("mongodb+srv ://<hostname>",
357359 authMechanism="MONGODB-AWS")
358360
359361 .. tab:: Connection String
360362 :tabid: connectionstring
361363
362364 .. code-block:: python
363365
364- uri = "mongodb://<hostname>:<port >/?&authMechanism=MONGODB-AWS"
366+ uri = "mongodb+srv ://<hostname>/?&authMechanism=MONGODB-AWS"
365367 client = pymongo.MongoClient(uri)
366368
367369For more information about using an ``AssumeRoleWithWebIdentity`` request to
@@ -391,15 +393,15 @@ You can set this option in two ways: by passing an argument to the
391393
392394 .. code-block:: python
393395
394- client = pymongo.MongoClient("mongodb://<hostname>:<port >",
396+ client = pymongo.MongoClient("mongodb+srv ://<hostname>",
395397 authMechanism="MONGODB-AWS")
396398
397399 .. tab:: Connection String
398400 :tabid: connectionstring
399401
400402 .. code-block:: python
401403
402- uri = "mongodb://<hostname>:<port >/?&authMechanism=MONGODB-AWS"
404+ uri = "mongodb+srv ://<hostname>/?&authMechanism=MONGODB-AWS"
403405 client = pymongo.MongoClient(uri)
404406
405407API Documentation
0 commit comments