- 최신
- 최다 투표
- 가장 많은 댓글
Hello,
Please try this solution.
To associate a MongoDB trigger with an AWS EventBridge event bus fellow below step.
To Create an AWS Lambda Function:
This function will forward MongoDB trigger events to EventBridge.
import json
import boto3
def lambda_handler(event, context):
eventbridge = boto3.client('events')
# Prepare and send the event to EventBridge
response = eventbridge.put_events(
Entries=[
{
'Source': 'mongodb.trigger',
'DetailType': 'MongoDB Trigger Event',
'Detail': json.dumps(event),
'EventBusName': 'test-event-bus-1' # Replace with your EventBus name
}
]
)
return {
'statusCode': 200,
'body': json.dumps('Event sent to EventBridge')
}
Deploy the Lambda Function:
Deploy the Lambda function and note its ARN.
Configure MongoDB Trigger:
Set up your MongoDB trigger to invoke the Lambda function. This sends MongoDB events to the Lambda function.
Update EventBridge Rule:
the EventBridge rule targets the Lambda function. Modify the existing rule or create a new one.
import boto3
session = boto3.Session(
aws_access_key_id='YOUR_ACCESS_KEY',
aws_secret_access_key='YOUR_SECRET_KEY',
region_name='YOUR_REGION'
)
eventbridge = session.client('events')
response = eventbridge.put_targets(
Rule='darwin-early-cancer-detection-crawl-job', # Your rule name
EventBusName='test-event-bus-1', # Your EventBus name
Targets=[
{
'Id': '1',
'Arn': 'arn:aws:lambda:your-region:your-account-id:function:your-lambda-function-name',
'InputPath': '$'
}
]
)
This setup forwards events from MongoDB triggers through a Lambda function to your EventBridge event bus, allowing you to integrate MongoDB events with AWS services.
https://aws.amazon.com/blogs/compute/ingesting-mongodb-atlas-data-using-amazon-eventbridge/
https://www.mongodb.com/docs/atlas/app-services/triggers/aws-eventbridge/
관련 콘텐츠
- AWS 공식업데이트됨 3년 전
Can I just use the code
directly in a single function which creates event bus and associates mongodb trigger with it?
Secondly, do i have to put the mongodb trigger details anywhere?