【问题标题】:AWS DocumentDB connection problem with TLSTLS 的 AWS DocumentDB 连接问题
【发布时间】:2020-04-21 12:07:17
【问题描述】:

禁用 TLS 后,我可以使用与此处所示相同的代码通过我的 lambda 函数成功连接 - https://docs.aws.amazon.com/documentdb/latest/developerguide/connect.html#w139aac29c11c13b5b7

但是,当我启用 TLS 并使用上述链接中启用 TLS 的代码示例时,我的 lambda 函数会超时。我已经通过 wget 下载了 rds 组合的 ca pem 文件,并且我正在将 pem 文件连同我的代码一起部署到 AWS lambda。

这是我的执行停止和超时的代码:

    caFilePath = "rds-combined-ca-bundle.pem"
    var connectionStringTemplate = "mongodb://%s:%s@%s:27017/dbname?ssl=true&sslcertificateauthorityfile=%s"
    var connectionURI = fmt.Sprintf(connectionStringTemplate, secret["username"], secret["password"], secret["host"], caFilePath)

    fmt.Println("Connection String", connectionURI)
    client, err := mongo.NewClient(options.Client().ApplyURI(connectionURI))
    if err != nil {
        log.Fatalf("Failed to create client: %v", err)
    }

打印“连接字符串”后,我在 cloudwatch 日志中没有看到任何错误。

【问题讨论】:

    标签: amazon-web-services go ssl aws-documentdb-mongoapi


    【解决方案1】:

    我怀疑这是您的 VPC 设计的问题

    从 Amazon VPC 外部连接到 Amazon DocumentDB 集群, 检查最后一段

    https://docs.aws.amazon.com/documentdb/latest/developerguide/connect-from-outside-a-vpc.html

    另外,下面的链接给出了详细的说明

    https://blog.webiny.com/connecting-to-aws-documentdb-from-a-lambda-function-2b666c9e4402

    【讨论】:

    • 如果是VPC,在没有启用TLS的情况下连接不应该失败吗?禁用 TLS 后,我可以连接到 DocumentDB。
    • 我知道你可以在没有 TLS 的情况下连接,尝试运行 > mongo --sslAllowInvalidHostnames --ssl --sslCAFile rds-combined-ca-bundle.pem --username --password
    • 抱歉,这是一个没有 lambda 的测试连接,如果您有 mongo 客户端,请确保它与 Lambda 无关
    • 是的,我可以使用 TLS 从另一个客户端连接到 DocumentDB 集群。它与 Lambda 相关,只能在禁用 TLS 时从 lambda 连接
    【解决方案2】:

    您可以尝试使用 python 创建 lambda 测试函数,看看您是否遇到问题

    import pymongo
    import sys
    
    ##Create a MongoDB client, open a connection to Amazon DocumentDB as a replica set and specify the read preference as secondary preferred
    client = pymongo.MongoClient('mongodb://<dbusername>:<dbpassword>@mycluster.node.us-east-1.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred') 
    
    ##Specify the database to be used
    db = client.test
    
    ##Specify the collection to be used
    col = db.myTestCollection
    
    ##Insert a single document
    col.insert_one({'hello':'Amazon DocumentDB'})
    
    ##Find the document that was previously written
    x = col.find_one({'hello':'Amazon DocumentDB'})
    
    ##Print the result to the screen
    print(x)
    
    ##Close the connection
    client.close()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-30
      • 2022-06-27
      • 2022-12-12
      • 2020-09-29
      • 2019-06-21
      相关资源
      最近更新 更多