MongoSecurityException - AWS-EKS - How to keep session alive

Hi,

I’ve successfully connected my application to MongoDB Atlas cluster from AWS-EKS using method described here: https://www.mongodb.com/docs/atlas/security/passwordless-authentication/#aws-eks

After some time the application fails with com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=MONGODB-AWS, userName='BLABLABLA', source='$external', password=<hidden>, mechanismProperties=<hidden>} when doing operations against Mongo.

Probably because it’s only a temporary client session. The IAM role has a maximum session duration of 1 hour. It seems it’s a bit random how long it takes before this MongoSecurityException kicks in.

Anyone has any experience with this and a recommended approach to solve this…? Haven’t found anything regarding this yet.

Don’t quite unterstand how this works…Just testet now with the k8s pod which has been running ~2 days without interruption (and no activity towards Mongo). I would expect it to get an MongoSecurityException when tries to do a operation towards Mongo. But everything worked perfectly.

Found this post which is related: Re-establish AWS Assumerole connection - but still unsure about a solution here.