{"id":13393161,"url":"https://github.com/cloudnative/lambda-chat","last_synced_at":"2025-03-13T19:31:27.716Z","repository":{"id":30798071,"uuid":"34355134","full_name":"cloudnative/lambda-chat","owner":"cloudnative","description":"A chat application without servers - using only AWS Lambda, S3, DynamoDB and SNS","archived":false,"fork":false,"pushed_at":"2016-03-29T17:27:36.000Z","size":318,"stargazers_count":388,"open_issues_count":6,"forks_count":64,"subscribers_count":21,"default_branch":"master","last_synced_at":"2024-10-26T18:29:43.104Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudnative.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-21T22:20:14.000Z","updated_at":"2024-02-22T13:19:08.000Z","dependencies_parsed_at":"2022-09-02T16:26:59.462Z","dependency_job_id":null,"html_url":"https://github.com/cloudnative/lambda-chat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudnative%2Flambda-chat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudnative%2Flambda-chat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudnative%2Flambda-chat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudnative%2Flambda-chat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudnative","download_url":"https://codeload.github.com/cloudnative/lambda-chat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243469145,"owners_count":20295694,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T17:00:44.340Z","updated_at":"2025-03-13T19:31:25.020Z","avatar_url":"https://github.com/cloudnative.png","language":"HTML","funding_links":[],"categories":["Open Source Repos","AWS Lambda Functions","[AWS Lambda](https://aws.amazon.com/lambda/)"],"sub_categories":["Lambda","[Examples]"],"readme":"# Lambda Chat\nA chat application without servers - using only AWS Lambda, S3, DynamoDB and SNS\n\n\n## Live Demo\n\nhttp://lambda-chat.s3-website-us-west-2.amazonaws.com/\n\nPlease don't send a million messages through here - it does cost us money and we will turn it off if it is abused.\n\n\n## How it works\n\n\n\u003cpre\u003e    ◎ ◎\n     ◡\n\n     │(1)\n     │                       ┏━━━━━━━━━━━━━━━━━━┓\n     │                       ┃                  ┃\n     │        (2)            ┃  Google OAuth2   ┃           (4)\n     │        ┌─────────────▶┃       API        ┃◀────────────┐\n     │        │              ┃                  ┃             │\n     │        │              ┗━━━━━━━━━━━━━━━━━━┛             │\n     ▼        ▼                                     ┏━━━━━━━━━━━━━━━━━━┓\n    ┏━━━━━━━━━━━━━━━━━━┓                            ┃                  ┃\n    ┃                  ┃ (3)                        ┃     AWS STS      ┃\n ┌─▶┃     Website      ┃◀──────────────────────────▶┃  AWS Web ID Fed  ┃\n │  ┃                  ┃                            ┃                  ┃\n │  ┗━━━━━━━━━━━━━━━━━━┛                            ┗━━━━━━━━━━━━━━━━━━┛\n │            │\n │            │        ┏━━━━━━━━━━━━━━━━━━┓\n │            │        ┃                  ┃\n │            └───────▶┃    SNS Topic     ┃\n │            (5)      ┃                  ┃\n │                     ┗━━━━━━━━━━━━━━━━━━┛\n │                               │\n │                               │       ┏━━━━━━━━━━━━━━━━━━┓\n │                               │       ┃                  ┃\n │                               └──────▶┃    Lambda fn1    ┃\n │                               (6)     ┃                  ┃\n │                                       ┗━━━━━━━━━━━━━━━━━━┛\n │                                                 │\n │                                                 │      ┏━━━━━━━━━━━━━━━━━━┓\n │                                                 │      ┃                  ┃\n │                                                 └─────▶┃  DynamoDB Table  ┃\n │                                                 (7)    ┃                  ┃\n │                                                        ┗━━━━━━━━━━━━━━━━━━┛\n │                                                                  │\n │                                    ┏━━━━━━━━━━━━━━━━━━┓          │\n │                                    ┃                  ┃          │\n │                                    ┃    Lambda fn2    ┃◀─────────┘\n │                                    ┃                  ┃        (8)\n │                                    ┗━━━━━━━━━━━━━━━━━━┛\n │                                              │\n │            ┏━━━━━━━━━━━━━━━━━━┓              │\n │            ┃                  ┃              │\n └────────────┃    S3 Object     ┃◀─────────────┘\n (10)         ┃                  ┃            (9)\n              ┗━━━━━━━━━━━━━━━━━━┛\n\n\nCreated with Monodraw\n\u003c/pre\u003e\n\n1.  The user opens their browser and go to the website which is hosted entirely on S3\n2.  The user signs in with their Google account and gets back an `id_token`\n3.  Using AWS Web Identity Federation in the Javascript SDK, the `id_token` is sent to get temporary AWS credentials from STS.\n4.  STS verifies the token with Google\n5.  The users types in a message, hits ENTER, and the website publishes the message to an SNS Topic.\n6.  A Lambda function is trigged by the SNS message, which gets the contents of the message, and...\n7.  Stores the message in a DynamoDB table\n8.  The process of adding a new chat message to the DynamoDB table triggers another Lambda function. This requires the currently-in-preview DynamoDB Streams feature. This second Lambda function reads the last 20 messages from DynamoDB, and... \n9. Writes them to an S3 object in JSON format\n10. The website polls the S3 object every second, and updates the chat box with any new messages it finds.\n\n\n## Getting Started\n\nThere is a lot involved here, but we have tried to make it as easy as possible for you to follow along.\n\n### Get the code\n\n    git clone git@github.com:cloudnative/lambda-chat.git\n    cd lambda-chat\n\n### Config\n\n    cp config.example.yml config.yml\n\nThe only thing to edit at this point is the name of the S3 bucket to put the website in as bucket names are globally unique.\n\n    s3_bucket: my-lambda-chat-bucket\n\n### Google OAuth\n\nTo be able to use AWS Web Identity Federation, you will need to create a new Google Project and create credentials.\n\n1.  Go to: https://console.developers.google.com/project\n1.  Create a new project\n1.  Enable **Google+ API**\n1.  Create OAuth 2 credentials. Leave the Javascript Origin empty for now\n1.  Edit `config.yml` and set `google_oauth_client_id` to your Client ID\n\n### AWS Resources\n\n#### Prerequisites\n\nYou will need Python 2.7. On OSX using brew\n\n    brew install python\n\nNow we need a few Python libraries\n\n    pip install -r requirements.txt\n\n#### CloudFormation\n\nThere is a script called `resources.py` which will generate a CloudFormation template to bring up the AWS resources needed to run Lambda Chat.\n\nYou can see the template by running\n\n    ./resources.py cf\n\nIf you are happy with that, the script can also launch the CloudFormation Stack. To create it in N. Virginia, run:\n\n    ./resources.py launch --region=us-east-1\n\nThe script returns quickly because it is now up to CloudFormation to bring up the AWS resources. Login to the AWS Web Console and go to the CloudFormation section in that region. Select the `Lambda-Chat` stack, then click on the **Events** tab to see the progress and check for errors.\n\nOnce the stack is complete, run:\n\n    ./resources.py output --region=us-east-1\n\nand add these values to your `config.yml` file.\n\n#### Website\n\nThe files needed to run the website need to be in S3. To get them there:\n\n    cd s3-website\n    ./update.sh\n\nYou can run this command as many times as you like, particularly if you are editing the files to see what is happening.\n\nThe script tells you the URL of the website. Open that up in your browser.\n\n#### Lambda functions\n\nTo help with the AWS Lambda side of things, we are using\n[kappa](https://github.com/garnaat/kappa).  Kappa is a CLI tool that helps with\nthe details of creating and managing AWS Lambda applications.  You must install\nkappa before proceeding.  You can install it from PyPI using pip:\n\n    % pip install kappa\n\nor you can clone the kappa repo and install locally:\n\n    % git clone git@github.com:garnaat/kappa.git\n    % cd kappa\n    % pip install -r requirements.txt\n    % python setup.py install\n\nNext, you must edit the config.yml files in the lambda/sns directory and the\nlambda/dynamodb  directories.  The config.yml files have comments which direct\nyou to the parts that need to be changed.\n\nNow create the components required for the SNS-\u003eDynamoDB Lambda function:\n\n1. cd lambda/sns\n1. run ``kappa config.yml create``\n1. run ``kappa config.yml invoke``.  This will call the AWS Lambda function\n   synchronously with test data and return the log data to the console.\n1. run ``kappa config.yml add_event_sources``.  This will connect the SNS topic\n   to your AWS Lambda function.\n\nFinally, you need to create the components requried for the DynamoDB-\u003eS3 Lambda\nfunction:\n\n1. cd lambda/dynamodb\n1. run ``kappa config.yml create``\n1. run ``kappa config.yml invoke``.  This will call the AWS Lambda function\n   synchronously with test data and return the log data to the console.\n1. run ``kappa config.yml add_event_sources``.  This will connect the DynamoDB\n   stream to your AWS Lambda function.\n\n\n### Usage\n\n1.  Go to the URL returned by the `update.sh` script, and login with your Google account.\n1.  Use like any other chat application :-)\n\n\n## Updating\n\nYou should feel free to mess around with this and update parts of it with your own code. If you do, please [let us know](https://twitter.com/intent/tweet?text=I%20am%20having%20fun%20with%20Lambda%20Chat.%20Thanks%20@CloudNativeIO).\n\nWhen you are making changes to the website, you can push them to S3 by running:\n\n    cd s3-website\n    ./update.sh\n\nFor modifications to the AWS Lambda functions, run:\n\n    % kappa config.yml update_code\n\nin the corresponding lambda directory.\n\n\n## Clean up\n\nDelete the CloudFormation stack\n\n    ./resources.py delete --region=us-east-1\n\nDelete the Lambda functions\n\n    % kappa config.yml delete\n\nin the corresponding lambda directory.  This will delete the AWS Lambda\nfunction, remove the event source mappings, and delete the IAM role.\n\n## Reading, resources and other stuff\n\n -  [The blog post that describes why we did this](https://cloudnative.io/blog/2015/05/lambda-chat/)\n -  [AWS Web Identity Federation playground](https://web-identity-federation-playground.s3.amazonaws.com/index.html)\n -  [Building Dynamic Dashboards Using Lambda and DynamoDB Streams: Part 1](https://medium.com/aws-activate-startup-blog/building-dynamic-dashboards-using-lambda-and-dynamodb-streams-part-1-217e2318ae17)\n -  [Kappa](https://github.com/garnaat/kappa)\n -  [Troposphere](https://github.com/cloudtools/troposphere)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudnative%2Flambda-chat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudnative%2Flambda-chat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudnative%2Flambda-chat/lists"}