简体   繁体   中英

AWS lambda getting 'unauthorized to perfrom action' when using MongoClient, works fine with mongoose, works fine when running command from shell

Here is the architecture: I have a MongoDB running on an EC2. When I ssh to the EC2 and run mongo dbname -u username -p password I am able to perform insert into the collection so that should mean that the user has permission in dbname to perform insert on collection

On the other side I have an AWS lambda, VPC is configured. When using mongodb.MongoClient to connect I am authenticated and client.isConnected() returns true but db.collection().insertOne(...) raises an error saying that I'm not authorized to perform action insert on dbname. The connection string used to connect contains the same username and password used to connect to mongo shell. I tried using the same options for connection to mongodb, but used mongoose instead and it didn't raise any errors

what is the connection string used? can you try to simulate what the lambda is doing locally? can you try connecting with local mongo client to your db using the same connection string that your lambda use?

are you connecting to the right db? is your user setup on your custom db or on the default admin db? are your update rights setup on the right db?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM