Issue connecting to Atlas with Node.js driver using AWS EC2 authentication

I’ve been working on a Next.js app that uses the latest MongoDB Node.js driver (4.11.0). It runs on AWS EC2 Amazon Linux 2.

Connection string:


This has worked without any issues for a while now. Today, I deployed a new version of my Next.js app, in which I also upgraded to next@13.0.3. No issues with the app overall localally (with local MongoDB server), but on AWS the app cannot connect to MongoDB Atlas anymore.


MongoAWSError: Cannot read properties of undefined (reading 'sso_session')
    at /apps/linksapp/node_modules/mongodb/lib/cmap/auth/mongodb_aws.js:192:22
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  [Symbol(errorLabels)]: Set(2) { 'HandshakeError', 'ResetPool' }

I didn’t change anything related to MongoDB. It suddenly just stopped working and from the error message I can’t work out, what’s wrong. I also didn’t change anything with the server config etc. The server was not restarted, just deployed a a new version of my app.

I have now changed the mechanism to MONGODB-X509 and it works again. I will keep it that way, but I just wanted to share what happened in case it’s not just me.

some parts of the code returns a null/undefined value thus causing this error.

and it seems related to auth and explains why your change has worked.

I am not pro for aws library so I can only guess the updated version has a breaking change. maybe you have missed an important upgrade note.

anyways, if it works, keep it that way until you find out what the actual problem is :slight_smile:

Looks like an issue with AWS Javascript SDK 3.209.0:

I rolled back to 3.208.0 and it worked fine for me.

You can see the same error with a simple script. First install the package:

npm install @aws-sdk/client-s3@3.209.0

Then run this script:

const { S3Client } = require("@aws-sdk/client-s3");
const { ListBucketsCommand } = require("@aws-sdk/client-s3");

const REGION = "us-east-1";
const s3Client = new S3Client({ region: REGION });

let run = async () => {
  try {
    const data = await s3Client.send(new ListBucketsCommand({}));
    console.log("Success", data.Buckets);
    return data; // For unit tests.
  } catch (err) {
    console.log("Error", err);
run().then(() => console.log("Done running"));
1 Like

I sometimes miss the obvious reason: breaking BUG :slight_smile:

It certainly makes sense, but I don’t even have any parts of the AWS SDK in my package.json. I assume, there may be an indirect dependency through mongodb@^4.11.0, but I can’t even see that. I have no idea what one is supposed to do here.

If you are using a recent version of npm, you can add an overrides property that allows you to override the versions of nested dependencies.

Needs npm 8.3 or later to work.