A serverless notification center using AWS Websocket API
Make sure you have enough permissions on your AWS account to:
- Create IAM roles
- Create/list s3 buckets
- Create/write to/read from DynamoDB tables
- Create/execute lambda functions
- Create/use lambda layers
- Create/list/write/read messages from SQS queues
- Create/send event from AWS Evenbridge
Make sure you have AWS SAM installed on your workspace and run the following command:
sam deploy --guided
Use postman to connect to your Websocket API. Use AWS EventBridge to send push notification to the clients.
All AWS infrastructures for this project are defined in template.yml
Handle authorization when client connect to the websocket API, you can write your own custom lambda authorizer. Custom authorizer have to return the policy document that specify the allowed actions on the specified resources.
return {
"principalId": claims["email"],
"policyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Action": "execute-api:Invoke",
"Effect": "Allow",
"Resource": event["methodArn"]
}]
},
"context": {
"userId": claims["email"]
}
}
Handle the create connection request from clients. In this example I insert the user_id and connection_id to a DynamoDB table.
Handle the delete connection request from clients. In this example I will delete the connection_id of when the client disconnect from the Websocket API.
Handle event when the server want to send notification to a specific user.