Hi guys,
You might solve this by listening to audit events and event bridge. We publish our audit events ( v2.audits.entitytype.USER.entityid.{id} ) to event bridge and event bridge allows us to wildcard all messages. so you don't have to subscribe to a specific user id (which is what is required in for a websockets notification).
Unfortunately, this event is not available for process automation triggers. If you need this event you might want to open an Idea in our Ideas portal asking for process automation trigger support.
Here are some thoughts on the eventbridge implementation. I used an AI to help generate the answer, so the process should be correct, but the code will need to be reviewed and checked. Take a look at this page as we have large amount of examples of how to setup events in eventbridge.
Thanks,
John Carnell
Director Developer, Engagement
Using the v2.audits.entitytype.USER.entityid.{id} topic with WebSocket notifications requires knowing the user ID upfront, which isn’t feasible for catching CREATE events for new users since their IDs aren’t known in advance. Switching to Amazon EventBridge integration with Genesys Cloud provides a better solution, as it supports wildcard-like behavior by allowing you to filter events based on patterns without needing to specify exact IDs.
Genesys Cloud can publish audit events to an AWS EventBridge event bus via an integration, and you can set up rules to capture user-related audit events (CREATE, UPDATE, DELETE) without requiring specific entityid values upfront. Below, I’ll provide a JavaScript implementation that processes these events using an AWS Lambda function triggered by EventBridge.
Approach
- Genesys Cloud Setup:
- EventBridge Rule:
-
Create an EventBridge rule to match user audit events (e.g., based on entityType: USER and actions like CREATE, UPDATE, DELETE).
-
Target the rule to an AWS Lambda function.
- Lambda Function:
- Write a JavaScript Lambda handler to process the events and log or act on user changes.
JavaScript Code Example (AWS Lambda)
javascript
// Lambda handler function
exports.handler = async (event) => {
try {
console.log('Received EventBridge event:', JSON.stringify(event, null, 2));
// Genesys Cloud audit events are sent as detail in the EventBridge event
const detail = event.detail;
// Extract relevant fields from the audit event
const entityType = detail.entityType; // Should be "USER"
const entityId = detail.entityId; // The user ID
const action = detail.action; // CREATE, UPDATE, DELETE
const initiatedBy = detail.initiatedBy?.displayName || 'Unknown'; // Who made the change
const timestamp = detail.timestamp; // When the change occurred
// Ensure the event is for a USER entity
if (entityType === 'USER') {
switch (action) {
case 'CREATE':
console.log(`User Created - ID: ${entityId}, By: ${initiatedBy}, At: ${timestamp}`);
// Add your logic here (e.g., save to DynamoDB, send SNS notification)
break;
case 'UPDATE':
console.log(`User Updated - ID: ${entityId}, By: ${initiatedBy}, At: ${timestamp}`);
// Add your logic here
break;
case 'DELETE':
console.log(`User Deleted - ID: ${entityId}, By: ${initiatedBy}, At: ${timestamp}`);
// Add your logic here
break;
default:
console.log(`Other action on user ${entityId}: ${action}, By: ${initiatedBy}, At: ${timestamp}`);
}
} else {
console.log(`Ignoring non-USER event: ${entityType}`);
}
return {
statusCode: 200,
body: JSON.stringify({ message: 'Event processed successfully' })
};
} catch (error) {
console.error('Error processing event:', error);
throw error; // Let Lambda retry or log the failure
}
};
Genesys Cloud EventBridge Integration Setup
- Create an EventBridge Integration:
-
In Genesys Cloud Admin UI, go to Integrations > Add Integration > Amazon EventBridge.
-
Provide your AWS Account ID, Region, and an optional Event Bus Name (default is default).
-
Activate the integration.
- Configure Event Filters:
-
In the integration settings, add a filter for User entity type audit events:
-
Save and activate the integration.
- Event Payload:
- Genesys Cloud sends audit events to EventBridge in a format like this:
json
{
"version": "0",
"id": "event-id",
"detail-type": "Genesys Cloud Audit Event",
"source": "genesys.cloud",
"account": "your-aws-account-id",
"time": "2025-03-21T12:00:00Z",
"region": "your-region",
"resources": [],
"detail": {
"entityType": "USER",
"entityId": "123e4567-e89b-12d3-a456-426614174000",
"action": "CREATE",
"initiatedBy": { "displayName": "Admin User" },
"timestamp": "2025-03-21T12:00:00Z"
}
}
EventBridge Rule Setup
- Create a Rule in AWS EventBridge:
json
{
"source": ["genesys.cloud"],
"detail": {
"entityType": ["USER"],
"action": ["CREATE", "UPDATE", "DELETE"]
}
}
- Target: Select your Lambda function (e.g., processGenesysUserEvents).
- Permissions:
- Ensure the Lambda function has an execution role with permissions to log to CloudWatch (AWSLambdaBasicExecutionRole).
Explanation
- Wildcard Advantage:
- Unlike the WebSocket approach, EventBridge doesn’t require subscribing to specific entityid values. The integration pushes all matching audit events to the event bus, and the rule filters them dynamically.
- Lambda Handler:
-
The handler processes each event, checking the entityType and action to determine if it’s a user-related CREATE, UPDATE, or DELETE.
-
You can extend the switch block with custom logic (e.g., writing to DynamoDB, sending an email via SES).
- Scalability:
- EventBridge and Lambda scale automatically, making this more robust than managing WebSocket connections.
Running the Solution
-
Deploy the Lambda:
-
Zip the JavaScript file and upload it to AWS Lambda, or use the inline editor.
-
Set the handler to index.handler (if the file is named index.js).
-
Test:
- Create, update, or delete a user in Genesys Cloud, then check CloudWatch Logs for the Lambda output.
Notes
-
Permissions: Ensure the Genesys Cloud integration has appropriate permissions to publish to EventBridge, and your AWS IAM role allows EventBridge to invoke Lambda.
-
Cost: EventBridge and Lambda have free tiers, but monitor usage for large-scale deployments.
-
Documentation: Refer to Genesys Cloud EventBridge Integration and AWS EventBridge for details.