-
Notifications
You must be signed in to change notification settings - Fork 948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Serverless Land Pattern waf-cloudfront-websocketapi-serverless #2560
New Serverless Land Pattern waf-cloudfront-websocketapi-serverless #2560
Conversation
git clone <repository-url> | ||
cd <repository-directory> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please put actual URL and path?
# Protecting WebSocket API with CloudFront and WAF Integration | ||
|
||
This pattern implements a secure WebSocket API using AWS CDK, integrating CloudFront for distribution and WAF for protection through AWS CDK with Python. It makes use of API keys to ensure that the Websocket endpoint can only be accessed via the CloudFront distribution by passing the API key as custom header from CloudFront. | ||
|
||
The WebSocket API provides real-time communication capabilities, while CloudFront ensures low-latency content delivery. The Web Application Firewall (WAF) adds an extra layer of security by protecting against common web exploits and controlling access based on configurable rules. | ||
|
||
![Alt text](images/architecturediagram.png?raw=true "Architecture Diagram for WebSocket API with CloudFront and WAF Integration") | ||
|
||
### Prerequisites | ||
|
||
- Python 3.9 or later | ||
- AWS CDK CLI | ||
- AWS CLI configured with appropriate credentials | ||
|
||
***Please note that AWS WAF is available globally for CloudFront distributions. So you must use the Region us-east-1 region while deploying the stack (N. Virginia)*** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refer other PRs to see template for README. It is recommended to put path for to-be serverlessland pattern in description.
## Data Flow | ||
|
||
The WebSocket API handles data flow as follows: | ||
|
||
1. Client initiates a WebSocket connection to the CloudFront distribution URL. | ||
2. CloudFront forwards the request to the API Gateway WebSocket API with the "x-api-key" as custom header. | ||
3. Websocket API validates the API key and routes the request based on the route selection expression. | ||
4. The Lambda function is invoked to handle the WebSocket event. | ||
|
||
``` | ||
[Client] <-> [CloudFront] <-> [API Gateway WebSocket API] <-> [Lambda Function] | ||
^ | | ||
| | | ||
+---------------------------------------------------------------+ | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally optional but if possible I'd recommend to add a flow diagram for explanation
…iagram along with repo url update in the pattern.json files
Issue #, if available:
Description of changes:
Created a serverless land pattern that implements a secure WebSocket API using AWS CDK, integrating CloudFront for distribution and WAF for protection through AWS CDK with Python. It makes use of API keys to ensure that the Websocket endpoint can only be accessed via the CloudFront distribution by passing the API key as custom header from CloudFront.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.