LambdaMessenger is a prototype for a serverless chat app using AWS AppSync, Node.js Lambda Functions, and DynamoDB. It was developed in an effort to evaluate AWS AppSync.
Check out the LambdaMessenger iOS app which uses these APIs.
Here is how the API works:
Register a user with the Firebase Authentication API:
const auth = firebase.auth();
auth.createUserWithEmailAndPassword(email, password)
auth.signInWithEmailAndPassword(email, password)
Save the user in DynamoDB:
const john = await api.registerUserWithEmail(userId, email, displayName);
const anthony = await api.registerUserWithEmail(userId, email, displayName);
Start up a conversation with other users:
const conversationId = await api.initiateConversation(john.userId, [anthony.userId])
Send a message to other users. By default, this will also send an push notification to the users in the conversation if they have a device token saved in their profile:
await api.postMessage(conversationId, john.userId, 'Hello')
Using GraphQL Subscriptions, messages can be retrieved realtime. See this unit test for an example of how to set up subscriptions.
LambdaMessenger is fully serverless, so a number of configuration steps are needed for AWS and Firebase to host the APIs.
- You'll need both a Firebase account and an AWS account in order to test and run this project. Firebase is used for its user authentication API (it integrates with AWS Appsync).
- Make sure you're running Node.js v8.10 or higher
- Install and configure the AWS CLI
The main settings for this project need to be specified in the config/config.json
file. Use the api/config.sample.json
as a baseline and rename it. You'll need to update this with your specific AWS and Firebase
settings.
{
"LAMBDA_IAM_ROLE": "arn:aws:iam::XXXXXX:role/XXXXXXXXX",
"CLOUDFORMATION_LAMBDA_STACK_NAME": "lambda-messenger-apis",
"LAMBDA_PACKAGE_S3_BUCKET": "lambda-messenger",
"APPSYNC_API_ID": "XXXXXXXXXXXXX",
"APPSYNC_ENDPOINT_URL": "https://XXXXXXXXXXXX.appsync-api.XXXXXXXXX.amazonaws.com/graphql"
}
- Configure Firebase
- Create an AWS IAM Role
- Create the AWS DynamoDB Tables
- Deploy AWS Lambda Functions
- Configure AWS AppSync
After Firebase and AWS are configured, the AppSync APIs can be tested using:
npx runjs test tests/apiTests.js # run local tests
npx runjs all && npm install && npm rebuild # Deploys everything
npx runjs tests # runs all tests, including integration tests
npx runjs all
, you'll need to re-run npm install
since the packaging process removes dev dependencies from node_modules
- John Robokos
This project is licensed under the MIT License - see the LICENSE.md file for details