Im trying to write to my documentDB using aws lambda and when trying to connect to the db I need to verify the cert and need to pass in the global bundle.pem into the mongo uri but it cant detect it.
import json
import pymongo
import os
CERTIFICATE_PATH = "/opt/global-bundle.pem"
MONGO_URI = f"mongodb://XXXX.cluster-chs6wio2st92.ap-XXX-X.docdb.amazonaws.com:27017/?tls=true&tlsCAFile=.{CERTIFICATE_PATH}&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false"
DATABASE_NAME = "XX"
COLLECTION_NAME = "XX"
client = pymongo.MongoClient(MONGO_URI)
db = client[DATABASE_NAME]
collection = db[COLLECTION_NAME]
def lambda_handler(event, context):
try:
trial_data = {
"trial_id": "1",
"name": "trial 1",
"description": "lambda db trial",
}
result = collection.insert_one(trial_data)
return {
'statusCode': 200,
'body': json.dumps({'message': 'Data inserted successfully', 'inserted_id': str(result.inserted_id)})
}
except Exception as e:
return {
'statusCode': 500,
'body': json.dumps({'error': str(e)})
}
I tried using layers and passed it in as a layer and read it from there but it doesnt seem to be able to work i get an error saying however on nosqlbooster it seems to work
[ERROR] FileNotFoundError: [Errno 2] No such file or directory: '/opt/global-bundle.pem'
Traceback (most recent call last):
New contributor
Nidhish Krishnan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.