mongodb / specifications

Specifications related to MongoDB
http://specifications.readthedocs.io/en/latest
Other
389 stars 242 forks source link

Unable to connect to mongodb atlas from ec2 instance, authentication using IAM ROLE #1467

Closed mihir9049 closed 1 year ago

mihir9049 commented 1 year ago

mongodb+srv://development.YYYYY.mongodb.net/testdb?authSource=%24external&authMechanism=MONGODB-AWS

We have a cluster setup on Mongo Atlas and above is the connection string to a DB in that cluster.

We have an EC2 instance in our aws a/c with an IAM role attached to it. We have a node application running on that instance and this uses the mongoose package to establish the DB connection.

We have also setup an IAM Role type user in the mongo cluster. So in theory my node app running on the EC2 should be able to connect to the mongo atlas DB using the above connection string - without my having to pass any keys or secrets. But this isn't working and i get an error like: MongoNetworkTimeoutError: Network request to http://169.254.169.254/latest/api/token timed out after undefined ms

This means - the application isn't able to retrieve the session token from the instance meta data.

I am though - able to connect to the DB from the same ec2 instance using mongosh. Which means that the IAM Role based authentication is working fine.

Am I missing something?

jmikola commented 1 year ago

@mihir9049: This repository is focused on cross-driver specifications and is not the appropriate forum for this kind of question. Please look into one of the support channels for the Node driver.