最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

java - Exception authenticating MongoCredential{mechanism=MONGODB-AWS, - Stack Overflow

matteradmin18PV0评论

I am using AWS IAM for connecting with Mongodb in Java Springboot. I have added aws v2 auth SDK, but I'm getting auth failure error. In logs I can see it's trying to use IAM but not working.

Springboot config:

spring:
  autoconfigure:
    exclude: .springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
  data:
    mongodb:
      uri: ${RESOURCE_MONGODB_URL:mongodb://127.0.0.1:27017/ab?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.8.2}&authMechanism=MONGODB-AWS
      database: ${RESOURCE_MONGODB_NAME}

Logs:

Monitor thread successfully connected to server with description ServerDescription{address=pl-0-us-east-2.xyxzz.mongodb:1024, type=REPLICA_SET_SECONDARY, cryptd=false, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=25, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=630044414, minRoundTripTimeNanos=0, setName='atlas-t268cg-shard-0', canonicalAddress=pl-0-us-east-2.xyxzz.mongodb:1024, hosts=[pl-0-us-east-2.xyxzz.mongodb:1025, pl-0-us-east-2.xyxzz.mongodb:1024, pl-0-us-east-2.xyxzz.mongodb:1026], passives=[], arbiters=[], primary='pl-0-us-east-2.xyxzz.mongodb:1025', tagSet=TagSet{[Tag{name='availabilityZone', value='use2-az1'}, Tag{name='diskState', value='READY'}, Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='US_EAST_2'}, Tag{name='workloadType', value='OPERATIONAL'}]}, electionId=null, setVersion=299, topologyVersion=TopologyVersion{processId=67c0450ca92b3a6506a4baf8, counter=4}, lastWriteDate=Fri Feb 28 10:51:39 GMT 2025, lastUpdateTimeNanos=4374084433883}

Using DefaultCredentialsProvider from AWS SDK v2 to retrieve AWS credentials. This is the recommended configuration

Checkout failed for connection to pl-0-us-east-2.xyxzz.mongodb:1025. Reason: An error occurred while trying to establish a new connection. Error: com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=MONGODB-AWS, userName='null', source='$external', password=<hidden>, mechanismProperties=<hidden>}. Duration: 537 ms```

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far