Code Monkey home page Code Monkey logo

chalice-websockets's Introduction

Websocket Connections in Chalice

Store connection ids in Postgres and send messages from Python to the browser

import requests, json
response = requests.get('http://35.233.160.178:3000/websocket_connections')
response
<Response [200]>
json.loads(response.content)
[{'id': 2,
  'namespace': 'default',
  'connection_id': 'x123',
  'timestamp': '2021-02-09T19:17:27.786349+00:00'},
 {'id': 5,
  'namespace': 'default',
  'connection_id': 'a123',
  'timestamp': '2021-02-09T19:31:00.991105+00:00'},
 {'id': 8,
  'namespace': 'default',
  'connection_id': 'a1234',
  'timestamp': '2021-02-09T19:31:24.973468+00:00'}]
response = requests.delete('http://35.233.160.178:3000/websocket_connections?connection_id=eq.a123')
response
<Response [204]>
response = requests.post('http://35.233.160.178:3000/websocket_connections', json={'connection_id': 'a123'})
response
<Response [201]>
%%time
import boto3
from boto3.session import Session
session = Session(profile_name='vbalasubramaniam_awscli')
connection_id = 'aftycfV1PHcCI7w='
apig = session.client('apigatewaymanagementapi', endpoint_url='https://akpgdwbu6b.execute-api.us-west-2.amazonaws.com/api/')
apig.post_to_connection(Data='hello from Jupyter', ConnectionId=connection_id)
CPU times: user 65.7 ms, sys: 22.8 ms, total: 88.5 ms
Wall time: 306 ms





{'ResponseMetadata': {'RequestId': '28035d50-9134-4778-82a7-c218ebd63b02',
  'HTTPStatusCode': 200,
  'HTTPHeaders': {'date': 'Tue, 09 Feb 2021 20:55:18 GMT',
   'content-type': 'application/json',
   'content-length': '0',
   'connection': 'keep-alive',
   'x-amzn-requestid': '28035d50-9134-4778-82a7-c218ebd63b02',
   'x-amz-apigw-id': 'aft8kFLOPHcFwUw=',
   'x-amzn-trace-id': 'Root=1-6022f6b6-05bf1e366c7d53a92ce36005'},
  'RetryAttempts': 0}}

chalice-websockets's People

Contributors

vbalasu avatar

Watchers

 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.