The AWS API Gateway WebSocket Integration Manager is a C# project that facilitates the management of AWS API Gateway WebSocket integrations for other projects. It provides a one-click deployment process, allowing users to quickly set up and use the project in their own AWS accounts.
To install the AWS API Gateway WebSocket Integration Manager, follow these steps:
- Create an S3 bucket in your AWS account to store the deployment package.
- Upload the
deploy.zip
file to the S3 bucket. This package contains the necessary files for deployment. - Deploy the dummy source code to AWS Lambda by executing the CloudFormation template provided in
template.yaml
. This sets up the required Lambda functions for the project.
The AWS API Gateway WebSocket Integration Manager consists of the following Lambda functions:
-
WebSocketAdaptorOnConnectFunction: This function is triggered when a client attempts to connect to the WebSocket. It stores the connection ID and user ID in DynamoDB.
-
WebSocketAdaptorOnDisconnectFunction: This function is triggered when a client disconnects from the WebSocket. It deletes the active connection ID for the user and logs the last activity date.
-
WebSocketAdaptorSendMessageFunction: This function listens to an SQS queue for sending socket messages to clients. The message structure is defined as follows:
public class MessageDomain
{
public string UserId { get; set; }
public string Body { get; set; }
}
The WebSocketAdaptorSendMessageFunction
requires the SendMessageQueueUrl
parameter to be set. You can configure the SendMessageQueueUrl
by providing the parameter name /WebSocketAdapter/SendMessageQueueUrl
.
-
WebSocketAdaptorAuthorizerFunction: This function handles the authorization process for connecting to the WebSocket using JSON Web Tokens (JWT). The JWT secret is stored in the Parameter Store with the name
/WebSocketAdapter/JwtSecret
. The JWT must contain auserId
claim for successful authorization. -
WebSocketAdaptorRestOnlineListFunction: This function provides online status or last activity date for users. When called without any parameters, it returns a list of online users. When
userIds
parameter is provided via the query string, the function returns the online status for the requested user IDs.
After deploying the project, two API Gateway instances will be created: one for WebSocket communication and another for HTTP API. You can obtain the URLs for these instances from the AWS Management Console.
The infrastructure setup for the AWS API Gateway WebSocket Integration Manager is provided as a CloudFormation template (template.yaml
). You can use this template for the initial setup of the infrastructure.
Example deployment pipelines using GitHub Actions are available in this repository. You can refer to these pipelines to set up your own CI/CD workflows for the project.
Here are some example cURL commands for making API requests to the deployed endpoints:
- Get online status for specific users:
curl -X GET "https://your-api-gateway-url/user/online?userIds=1234"
Replace https://your-api-gateway-url
with the actual URL of your deployed API Gateway WebSocket instance.
- WebSocket Connection:
wscat -c "wss://your-socket-url?Authorization=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwidXNlcklkIjoiMTIzNCIsImlhdCI6MjAxNjIzOTAyMiwiZXhwIjoyMDE2MjM5MDIyfQ.6C7xpaC9_vmadA72tABVkqXH9HWcPY4RE8dGALnT-Hw"
Make sure to replace your-socket-url
with the actual WebSocket URL of your deployed API Gateway instance and eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwidXNlcklkIjoiMTIzNCIsImlhdCI6MjAxNjIzOTAyMiwiZXhwIjoyMDE2MjM5MDIyfQ.6C7xpaC9_vmadA72tABVkqXH9HWcPY4RE8dGALnT-Hw
with your actual JWT token.
Please note that the wscat
tool is used to establish the WebSocket connection, and you may need to install it separately if you haven't already.
Let me know if you have any further questions!
Ensure you have the wscat
tool installed to establish a WebSocket connection.
- Fehmi Anaç - Project Lead