Created
July 4, 2026 15:30
-
-
Save nivleshc/79b80953d9ecd645efab847a6cd550b1 to your computer and use it in GitHub Desktop.
This gist contains the code for publishing to EventBridge from lambda-function.py, which is part of the blog-amazon-macie-custom-eventbridge-events repository.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def publish_to_eventbridge(job_status_event): | |
| """ | |
| Publish a custom event to Amazon EventBridge. | |
| The event is published with: | |
| - Source: custom.macie.job-status | |
| - DetailType: Macie Classification Job Status Change | |
| - Detail: The full job status event data as JSON | |
| Parameters: | |
| job_status_event (dict): The parsed job status event data | |
| Returns: | |
| bool: True if the event was published successfully, False otherwise | |
| """ | |
| try: | |
| response = eventbridge_client.put_events( | |
| Entries=[ | |
| { | |
| "Source": EVENT_SOURCE, | |
| "DetailType": DETAIL_TYPE, | |
| "Detail": json.dumps(job_status_event), | |
| "EventBusName": EVENT_BUS_NAME | |
| } | |
| ] | |
| ) | |
| # Check if the event was published successfully | |
| failed_count = response.get("FailedEntryCount", 0) | |
| if failed_count > 0: | |
| entries = response.get("Entries", []) | |
| for entry in entries: | |
| if "ErrorCode" in entry: | |
| logger.error( | |
| f"Failed to publish event: " | |
| f"ErrorCode={entry.get('ErrorCode')}, " | |
| f"ErrorMessage={entry.get('ErrorMessage')}" | |
| ) | |
| return False | |
| return True | |
| except Exception as e: | |
| logger.error(f"Error publishing event to EventBridge: {str(e)}") | |
| return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment