我在 AWS Elastic Beanstalk (EB) 中有 2 个环境,运行 Node.js 应用程序,使用 Mongoose 框架连接到 DocumentDB。其中一个环境莫名其妙地停止工作,而另一个环境工作正常。两者都是从 CI/CD 构建服务器部署的,该服务器使用 EB CLI 来部署应用程序代码。
有问题的环境在nodejs.log中产生如下错误:
name: 'MongooseTimeoutError',
reason:
{ Error: unable to get local issuer certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1058:34)
at TLSSocket.emit (events.js:198:13)
at TLSSocket._finishInit (_tls_wrap.js:636:8)
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {} },
[Symbol(mongoErrorContextSymbol)]: {} }
Run Code Online (Sandbox Code Playgroud)
两者都使用相同的连接字符串,因为它们连接到同一个实例 mongodb://*****:*****@docdb-2019-08-**-**-**-**.cluster-**********.us-east-2.docdb.amazonaws.com:27017/db_name?ssl=true&ssl_ca_certs=/etc/ssl/certs/rds-combined-ca-bundle.pem&replicaSet=rs0
证书 pem 文件是用于两者的相同文件,并通过 EB .ebextensions 脚本部署到实例。
我尝试过的事情:
目前有点卡住了想法。
mongoose node.js amazon-elastic-beanstalk aws-documentdb-mongoapi aws-documentdb
有什么办法可以让这个操作更快?
我正在尝试将我的数据库恢复到 AWS DocumentDB,可能需要几周时间才能完成……我的总体数据不到 400MB。
转储是 Gzip 压缩的
我们正在尝试在无服务器中构建在 Express 上的 lambda 中连接到 AWS DocumentDB。为此,我们使用 mongoose 和一个看起来像的连接函数
import mongoose from 'mongoose';
import logger from './utils/logger';
import fs from 'fs';
const READYSTATE_CONNECTED = 1;
const mongoDB = process.env.MONGODB_URI;
const certificateFilePath = __dirname + '/rds-combined-ca-bundle.pem';
logger.info(`Loading certificate file from ${certificateFilePath}`);
let ca = [fs.readFileSync(certificateFilePath)];
logger.info('Connection is ' + mongoose.connection.readyState);
if (mongoose.connection.readyState !== READYSTATE_CONNECTED) {
logger.info(`Connecting to mongo using env connection string ${mongoDB}`);
mongoose.connect(mongoDB, { useNewUrlParser: true, useUnifiedTopology: true, checkServerIdentity: false, ssl: true, sslCA: ca }).catch((err) => {
logger.error(`Unable to connect …Run Code Online (Sandbox Code Playgroud) 我正在努力在非默认 VPC 中设置 AWS DocumentDB 集群。我创建了一个包含 1 个公有子网和 3 个私有子网的新 VPC。3 个私有子网均位于不同的可用区,并分组在一个子网组中。不过,当我尝试创建新的 DocumentDB 集群时,我只能选择默认 VPC。我错过了什么吗?据我所知,我满足官方文档中列出的所有 VPC 要求:https://docs.aws.amazon.com/documentdb/latest/developerguide/db-cluster-create.html
我有一个AWS DocumentDB设置,我可以使用以下命令通过我的跳转框连接到:
mongo --ssl --host aws-host:27017 --sslCAFile rds-combined-ca-bundle.pem --username my_user --password <insertYourPassword>
Run Code Online (Sandbox Code Playgroud)
我希望能够通过 localhost 连接到它进行一些测试。我无法直接连接,所以我试图从我的跳跃中打开一个隧道:
ssh -i ~/.ssh/my-key user@my_jump -L 27017:aws-host:27017 -N
Run Code Online (Sandbox Code Playgroud)
之后,我尝试了基本的 MongoDB 连接命令:
mongo --ssl --host localhost:27017 --sslCAFile rds-combined-ca-bundle.pem --username my_user --password <insertYourPassword>
Run Code Online (Sandbox Code Playgroud)
我收到一个我理解的错误:
服务器证书与主机名不匹配。主机名:本地主机与 SAN 不匹配
我尝试export http_proxy使用http://my_jump:27017并再次使用上面的命令,但没有成功。
有关如何连接的任何建议或帮助?
How do I connect to Amazon's new DocumentBD database from node.js (In this case, using an out-of-the-box Elastic Beanstalk setup.)
This is my code, copied from the docs (with some values altered for privacy). It just times out and the eventual value of 'err' is 'true'. What did I miss? How can I get a better error?
var MongoClient = require('mongodb').MongoClient,fs = require('fs');
var ca = [fs.readFileSync("rds-combined-ca-bundle.pem")];
var connection_string = "mongodb://USERNAME:PASSWORD@docdb-2019-04-23-12-55-44.cluster-abcdefghij.eu-west-1.docdb.amazonaws.com:27017/?ssl=true&&replicaSet=rs0&readPreference=secondaryPreferred";
MongoClient.connect(
connection_string, {
sslValidate: true,
sslCA: ca,
useNewUrlParser: true …Run Code Online (Sandbox Code Playgroud) amazon-web-services node.js amazon-elastic-beanstalk aws-documentdb-mongoapi aws-documentdb
我正在按照 aws 建议使用以下命令来下载 rds-combined-ca-bundle.pem 文件并连接到集群。
wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem
mongo --ssl --host docdb-2021-03-29-09-23-57.cluster-cqwdgjnpay32.ap-south-1.docdb.amazonaws.com:27017 --sslCAFile rds-combined-ca-bundle.pem --用户名 docudbadmin --密码 *****
得到以下内容
错误:无法连接到服务器 docdb-2021-03-29-09-23-57.cluster-cqwdgjnpay32.ap-south-1.docdb.amazonaws.com:27017,连接尝试失败:HostUnreachable:连接由对等方重置: connect@src/mongo/shell/mongo.js:353:17 @(connect):2:6 异常:连接失败
但是,如果不在集群组中启用 tls 和 tls_monitor 参数,我就可以通过 mongo shell 从 ec2 连接。
我为我们的预生产环境创建了一个新的 VPC,并尝试在其中创建一个 DocumentDB 集群。
根据https://docs.aws.amazon.com/documentdb/latest/developerguide/db-cluster-create.html 上的 VPC 先决条件,我需要确保在新的 3 个不同的可用区中至少有 3 个子网VPC 这样做。
但是,当我尝试创建它时,我的新 VPC 不是可用的选择。我错过了什么?
正如我们从下面的屏幕截图中看到的,VPC 在 1a 1b 和 1d 中有一个私有子网,但我的新数据库集群无法选择它
提前致谢!
我不知道为什么 AWS DocumentDb 不支持 3.6 以上的 MongoDB 版本?我应该使用 mongo 3.6 还是 4.0 以上?
我有一个架构如下:
var answerSchema = new mongoose.Schema({
username: {
type: String,
unique: true,
required: true
}
)
mongoose.model("Answer", answerSchema)
Run Code Online (Sandbox Code Playgroud)
在另一个文件中我有:
var Answer = mongoose.model("Answer")
router.put("/test", function (req, res){
const query = { _id: "5fe656077ddb2a4e1a91d808"}
const update = { username: 'test' }
const options = {
new: true,
upsert: true,
setDefaultsOnInsert: true
}
Answer.findOneAndUpdate(query, update, options, function(error, doc) {
if(error){
res.send(error.message)
}
else{
res.send('successfully saved.')
}
})
})
Run Code Online (Sandbox Code Playgroud)
目前在 mongo shell 中,我可以运行 db.answers.find().pretty() 它给了我:
{
"_id" : ObjectId("5fe656077ddb2a4e1a91d808"),
"username" : "aaaa",
"__v" …Run Code Online (Sandbox Code Playgroud) aws-documentdb ×10
mongodb ×3
mongoose ×3
node.js ×3
amazon-vpc ×2
javascript ×1
mongorestore ×1
serverless ×1
ssh-tunnel ×1