This solution provides an advanced financial fraud detection system that leverages generative AI and AWS services. It focuses on preprocessing and transforming financial transaction data to enhance fraud detection capabilities. The system utilizes a series of data transformation steps, implemented as AWS Lambda functions, and orchestrated through an Amazon Bedrock agent.
- Data preprocessing pipeline for fraud detection datasets
- Generation of a data report to inform you about the input dataset
- Utilization of AWS Lambda for scalable data transformations
- Integration with Amazon Bedrock for intelligent orchestration
- Amazon Kendra integration with Bedrock for searching fraud-related documentation (optional due to regional availbility; will have to uncomment in the backend-stack.ts if you want to deploy it)
- Customizable data transformation steps including:
- Dropping unnecessary columns
- Converting text to lowercase
- Cleaning entity IDs
- Converting timestamps
- Encoding categorical variables
- One-hot encoding of fraud indicators
- Adding event timestamps Feel free to add more tailored to the data that you are planning to input.
-
WebSocket API Gateway
- WebSockets: enables real-time bidirectional communication between clients and servers through a persistent connection, ideal for applications requiring live updates like chat or gaming.
- Timeout Handling: API Gateway has integration timeouts, so async functions like the message handler are used to manage longer-running operations like chat requests
- Benefits: Real-time streaming responses, better user experience, reduced latency, persistent connections
-
WebSocket Lambda Handlers (backend/lambda/websocket/)
- Connect Handler (
connect_handler.py): Manages WebSocket connections and initialization - Disconnect Handler (
disconnect_handler.py): Handles cleanup and state management on disconnection - Message Handler (
message_handler.py): Routes incoming messages and dispatches to appropriate handlers - Streaming Chat Handler (
streaming_chat_handler.py): Processes Bedrock agent requests and streams responses in real-time chunks
- Connect Handler (
-
Real-time Streaming Capabilities
- Chunked streaming responses as they're generated by Bedrock
- Benefits: Progressive content delivery, better perceived performance, real-time trace information
-
Unified Message Routing
- Message-based routing through single WebSocket connection
- Benefits: Support for multiple message types (chat, list operations), extensible architecture
- Chat Flow: User sends message via WebSocket → Message Handler routes → Streaming Chat Handler processes → Bedrock Supervisor Agent → Responses streamed back in real-time chunks
- List Operations: Frontend sends list request via WebSocket → Message Handler routes to appropriate list function → Response sent back through WebSocket
- Connection Management: Persistent WebSocket connections with proper lifecycle management (connect/disconnect handlers)
The WebSocket implementation maintains session continuity and provides real-time bidirectional communication while supporting both chat interactions and data listing operations through a unified interface.
The FSI Fraud Detection solution leverages AWS services and generative AI to:
- Process and analyze financial transactions in real-time
- Detect potential fraudulent patterns using machine learning
- Provide interactive fraud investigation capabilities through a React-based web interface
- Secure access through AWS Cognito authentication
- Deploy infrastructure as code using AWS CDK
Before deploying this solution, ensure you have the following:
-
AWS Account Access
- An AWS account with administrative permissions
- AWS CLI installed and configured with your credentials
-
Development Tools
- Node.js 18.x or later
- npm 8.x or later
- AWS CDK CLI (can be installed via
npm install -g aws-cdk) - Git (for cloning the repository)
-
AWS Configuration
- Code currently only supports us-east-1
Follow these steps to deploy the solution in your AWS account:
-
Clone the Repository
git clone <repository-url> cd scale-fsi-fraud-detection-gen-ai
-
Install Dependencies
# Install backend dependencies cd backend npm install
-
Deploy the Backend Stack
# Ensure you're in the backend directory cdk bootstrap cdk synth cdk deployDuring deployment, CDK will:
- Create necessary IAM roles and permissions
- Deploy Lambda functions
- Set up API Gateway endpoints
- Configure Cognito user pool
- Create required DynamoDB tables
-
Configure Environment Variables After the stack deployment completes, you'll receive various outputs from CloudFormation. Update the
.envfile in the chatbot directory with these values:REACT_APP_AWS_REGION=us-east-1 REACT_APP_COGNITO_USER_POOL_ID=<TODO> REACT_APP_COGNITO_CLIENT_ID=<TODO> REACT_APP_COGNITO_DOMAIN=<TODO> REACT_APP_REDIRECT_SIGNIN=http://localhost:3000/ REACT_APP_REDIRECT_SIGNOUT=http://localhost:3000/ REACT_APP_API_GATEWAY_ENDPOINT=<TODO> REACT_APP_WEBSOCKET_ENDPOINT=<TODO> -
Verify Deployment
- Check the AWS Console to ensure all resources are created correctly
- Test the API Gateway endpoints using the provided URLs
- Verify Cognito user pool configuration
-
Access the Application
cd chatbot-app npm install npm start- Create user on sign up
- Verify all functionality is working as expected
To avoid incurring unnecessary AWS charges, you can remove the deployed resources:
cd backend
cdk destroyDouble check that all resources have been destroyed especially the S3 bucket.
For support, please open an issue in the repository. Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
- Ragib Ahsan, AWS AI Acceleration Architect
- Keith Lee, AWS Partner Solutions Architect
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.
