Skip to content

Instantly share code, notes, and snippets.

@yai333
Created March 6, 2019 09:46
Show Gist options
  • Save yai333/f0b611a271dcc7ccec9f167b73ae5996 to your computer and use it in GitHub Desktop.
Save yai333/f0b611a271dcc7ccec9f167b73ae5996 to your computer and use it in GitHub Desktop.
service: serverless-chat
provider:
name: aws
runtime: nodejs8.10
stackName: ${self:service}-${self:provider.stage}
stage: ${opt:stage, 'dev'}
region: ${opt:region, 'ap-southeast-2'}
iamRoleStatements:
- Effect: Allow
Action:
- "execute-api:ManageConnections"
Resource:
- "arn:aws:execute-api:*:*:**/@connections/*"
- Effect: Allow
Action:
- "dynamodb:PutItem"
- "dynamodb:GetItem"
- "dynamodb:UpdateItem"
- "dynamodb:DeleteItem"
- "dynamodb:Query"
- "dynamodb:Scan"
Resource:
- Fn::GetAtt: [ChatConnectionsTable, Arn]
- Fn::Join:
- "/"
- - Fn::GetAtt: [ChatConnectionsTable, Arn]
- "*"
environment:
CHATCONNECTION_TABLE:
Ref: ChatConnectionsTable
websocketApiName: websocket-chat-${self:provider.stage}
websocketApiRouteSelectionExpression: $request.body.action
functions:
connectionManager:
handler: handler.connectionManager
events:
- websocket:
route: $connect
authorizer: authorizerFunc # references the authorizerFunc function below
- websocket:
route: $disconnect
authorizerFunc:
handler: handler.authorizerFunc
defaultMessages:
handler: handler.defaultMessage
events:
- websocket:
route: $default
sendMessage:
handler: handler.sendMessage
events:
- websocket:
route: sendMessage
resources:
Resources:
ChatConnectionsTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: connectionId
AttributeType: S
KeySchema:
- AttributeName: connectionId
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment