Coder Social home page Coder Social logo

apigateway-websockets-lambda's Introduction

apigateway-websockets-lambda

Sample repository for using API gateway to handle lambda websockets

Steps

1. Create default ECR repository

Use the following to create a default ECR repository in your region:

dg env create default --target diggerhq/target-lambda@default
dg env apply default
# This is needed to create an initial image in the repository (you can select any service)
dg env build
dg env push

Once this command is done you will see a docker_registry as output. You can copy that value and append :latest to it. Create a file digger.config.yml and include the following contents in it:

default:
  image_uri: "<<account_id>>.dkr.ecr.eu-central-1.amazonaws.com/lambda-default:latest"

2. Create an environment

Use the following commands to create the environment with your services:

dg env create test --target diggerhq/target-lambda@ws
dg env apply test

3. Create DynamoDB table

Create a DynamoDB table with a name of your chooice. Next, you can configure the environment variables as follows:

Screenshot 2021-05-24 at 22 28 45

over in app.digger.dev, create the following environment variable with TABLE_NAME={your_table_name}

Screenshot 2021-05-24 at 22 30 54

4. Release your services

# (select any service)
dg env build test
dg env push test
# do the release for all services
dg env release test

4. Configure API gateway

The template will create an API Gateway with the name of {project_name}-{environment_name}

You need to link three endpoints to your corresponding three services: onConnect, onDisconnect and sendMessage

Screenshot 2021-05-24 at 22 31 44

Finally you need to deploy your API. Create a new stage (example Default). Note down the API Gateway URL as well as the stage name for the next step.

5. Test the websocket connection

For this step you can use the Gateway Endpoint as well as the stage as you have noted them down in the next step. You can test using wscat:

npm install -g wscat
$ wscat -c wss://{YOUR-API-ID}.execute-api.{YOUR-REGION}.amazonaws.com/{STAGE}

Send message and check that it is received from other clients:

$ wscat -c wss://{YOUR-API-ID}.execute-api.{YOUR-REGION}.amazonaws.com/prod
connected (press CTRL+C to quit)
> {"action":"sendmessage", "data":"hello world"}
< hello world

Acknowledgements

Thanks to Simple websockets chat app for the inspiration: https://github.com/aws-samples/simple-websockets-chat-app

apigateway-websockets-lambda's People

Contributors

motatoes avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.