确认 Lambda 函数的 VPC 配置是否正确,包括安全组和子网的设置。建议将 Lambda 函数放在至少两个子网中,并在安全组中允许 MongoDB 的端口流量通过。
确认角色是否有正确的 Amazon DocumentDB 权限。为 Lambda 函数提供 AWS 允许所需的 IAM 权限,并执行相关的 IAM 设置以对 Amazon DocumentDB 进行访问。
检查您的 Python 代码是否在 pymongo 驱动程序中使用了正确的输入参数,如下所示:
import boto3
import pymongo
client = boto3.client('ssm')
parameters = client.get_parameters(
Names=['my_mongodb_url'], WithDecryption=True)
mongodb_url = parameters['Parameters'][0]['Value']
client = pymongo.MongoClient(mongodb_url)
db = client['my_database']
collection = db['my_collection']
collection.delete_many({})
import boto3
import pymongo
client = boto3.client('ssm')
parameters = client.get_parameters(
Names=['my_mongodb_url'], WithDecryption=True)
mongodb_url = parameters['Parameters'][0]['Value']
client = pymongo.MongoClient(mongodb_url)
db = client['my_database']
collection = db['my_collection']
result = collection.delete_many({})
print("Number of documents deleted:", result.deleted_count)