Skip to content

phamdinhha/serverless-notification-center

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serverless websocket notification center

A serverless notification center using AWS Websocket API

alt text

Installation

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

Testing

Use postman to connect to your Websocket API. Use AWS EventBridge to send push notification to the clients.

AWS infrastructures

All AWS infrastructures for this project are defined in template.yml

Lamdas

Authorizer

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"]
    }
}

Create socket connection

Handle the create connection request from clients. In this example I insert the user_id and connection_id to a DynamoDB table.

Delete socket connection

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.

Notify users

Handle event when the server want to send notification to a specific user.

About

A serverless notification on AWS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages