Skip to content

Instantly share code, notes, and snippets.

View annacoding2020's full-sized avatar

Anna Coding annacoding2020

View GitHub Profile
@annacoding2020
annacoding2020 / serverless.yml
Last active January 25, 2020 19:52
AWS API Gateway WebSocket API with the Serverless Framework to Fulfill Front-end Real-time Update
Functions:
websocket:
handler: src/websocket.handler
events:
- websocket:
# Handles new connection requests
route: $connect
- websocket:
# Handles all unrouted messages
@annacoding2020
annacoding2020 / serverless.yml
Last active January 25, 2020 20:09
AWS API Gateway WebSocket API with the Serverless Framework to Fulfill Front-end Real-time Update
provider:
name: aws
runtime: nodejs12.x
environment:
API_GATEWAY_ENDPOINT:
Fn::Join:
- ''
- - Ref: WebsocketsApi
- .execute-api.
- Ref: AWS::Region
const AWS = require('aws-sdk')
const apig = new AWS.ApiGatewayManagementApi({
endpoint: process.env.API_GATEWAY_ENDPOINT
})
const dynamodb = new AWS.DynamoDB.DocumentClient()
const Your_Table_NAME = process.env.CONNECTIONS_TABLE
@annacoding2020
annacoding2020 / serverless.yml
Created January 25, 2020 20:36
AWS API Gateway WebSocket API with the Serverless Framework to Fulfill Front-end Real-time Update
resources:
Resources:
# Your Table Name
connectionsTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
Properties:
TableName: ${self:custom.YourTableName}
AttributeDefinitions:
- AttributeName: connectionId
@annacoding2020
annacoding2020 / serverless.yml
Created January 25, 2020 20:45
AWS API Gateway WebSocket API with the Serverless Framework to Fulfill Front-end Real-time Update
custom:
websocketArn:
Fn::Join:
- ':'
- - arn:aws:dynamodb
- Ref: AWS::Region
- Ref: AWS::AccountId
- table/${self:custom.YourTableName}
resources:
@annacoding2020
annacoding2020 / broadcast.tsx
Created January 25, 2020 21:08
AWS API Gateway WebSocket API with the Serverless Framework to Fulfill Front-end Real-time Update
const AWS = require('aws-sdk')
const apig = new AWS.ApiGatewayManagementApi({
endpoint: process.env.APIG_ENDPOINT
})
const dynamodb = new AWS.DynamoDB.DocumentClient()
const YourTable = process.env.CONNECTIONS_TABLE
@annacoding2020
annacoding2020 / Carousel.jsx
Created January 27, 2020 09:31
React Multiple Items Carousel with Server Side Rendering Support - part one
@annacoding2020
annacoding2020 / Carousel.js
Created January 27, 2020 12:54
React Multiple Items Carousel with Server Side Rendering Implementation (Part two)