Nick
(Nick Singleton)
November 13, 2022, 8:34pm
1
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:
mongodb+srv://xxx.yyy.mongodb.net/?authSource=%24external&authMechanism=MONGODB-AWS
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.
Error:
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
Looks like an issue with AWS Javascript SDK 3.209.0:
opened 10:43PM - 13 Nov 22 UTC
closed 12:02AM - 03 Dec 22 UTC
bug
closed-for-staleness
p0
### Checkboxes for prior research
- [X] I've gone through [Developer Guide](h… ttps://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide) and [API reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest)
- [X] I've checked [AWS Forums](https://forums.aws.amazon.com) and [StackOverflow](https://stackoverflow.com/questions/tagged/aws-sdk-js).
- [X] I've searched for [previous similar issues](https://github.com/aws/aws-sdk-js-v3/issues) and didn't find any solution.
### Describe the bug
Start getting this error when deploying to AWS Elastic Beanstalk. I am trying to access Secret Manager.
### SDK version number
"@aws-sdk/client-secrets-manager": "^3.209.0"
### Which JavaScript Runtime is this issue in?
Node.js
### Details of the browser/Node.js/ReactNative version
v16.18.0
### Reproduction Steps
1. Deploy the AWS Secret Manager node.js sample code to Elastic Beanstalk.
2. You will see the error when trying to get the secret.
### Observed Behavior
```
Nov 13 22:30:24 ip-10-0-2-9 web: TypeError: Cannot read properties of undefined (reading 'sso_session')
Nov 13 22:30:24 ip-10-0-2-9 web: at /var/app/current/node_modules/@aws-sdk/credential-provider-sso/dist-cjs/fromSSO.js:15:21
Nov 13 22:30:24 ip-10-0-2-9 web: at async coalesceProvider (/var/app/current/node_modules/@aws-sdk/property-provider/dist-cjs/memoize.js:14:24)
Nov 13 22:30:24 ip-10-0-2-9 web: at async SignatureV4.credentialProvider (/var/app/current/node_modules/@aws-sdk/property-provider/dist-cjs/memoize.js:33:24)
Nov 13 22:30:24 ip-10-0-2-9 web: at async SignatureV4.signRequest (/var/app/current/node_modules/@aws-sdk/signature-v4/dist-cjs/SignatureV4.js:86:29)
Nov 13 22:30:24 ip-10-0-2-9 web: at async /var/app/current/node_modules/@aws-sdk/middleware-signing/dist-cjs/middleware.js:16:18
Nov 13 22:30:24 ip-10-0-2-9 web: at async StandardRetryStrategy.retry (/var/app/current/node_modules/@aws-sdk/middleware-retry/dist-cjs/StandardRetryStrategy.js:51:46)
Nov 13 22:30:24 ip-10-0-2-9 web: at async /var/app/current/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:6:22
Nov 13 22:30:24 ip-10-0-2-9 web: at async getAWSSecrets (/var/app/current/packages/server/dist/infrastructure/settings/config.factory.js:104:21)
Nov 13 22:30:24 ip-10-0-2-9 web: at async InstanceWrapper.ConfigAWSFactory [as metatype] (/var/app/current/packages/server/dist/infrastructure/settings/config.factory.js:61:21)
Nov 13 22:30:24 ip-10-0-2-9 web: at async Injector.instantiateClass (/var/app/current/node_modules/@nestjs/core/injector/injector.js:344:37)
```
### Expected Behavior
Retrieve the secret without errors.
### Possible Solution
Probably caused by this change https://github.com/aws/aws-sdk-js-v3/pull/4145/files#r1020812785 on https://github.com/aws/aws-sdk-js-v3/pull/4145
@kuhe
### Additional Information/Context
_No response_
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
Nick
(Nick Singleton)
November 14, 2022, 12:58pm
5
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.