Last active
December 23, 2021 02:06
-
-
Save Jimeux/6bbe4933d8aad0040deb261cfe8a40be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: sls-svc-ws | |
frameworkVersion: '2' | |
provider: | |
name: aws | |
runtime: go1.x | |
lambdaHashingVersion: 20201221 | |
stage: dev | |
region: ap-northeast-1 | |
websocketsApiName: chat-api-websocket-api | |
# The route selection expression | |
websocketsApiRouteSelectionExpression: $request.body.action | |
environment: | |
# CLI options can be accessed with opt | |
STAGE: ${opt:stage, 'dev'} | |
# Generated CloudFormation resources can be referenced | |
# using CloudFormation syntax. Refer to JSON files in | |
# generated .serverless directory for resources names. | |
API_GATEWAY_DOMAIN: | |
Fn::GetAtt: [ WebsocketsApi, ApiEndpoint ] | |
# CloudFormation resources defined in the Resources | |
# section can also be accessed. | |
CONNECTIONS_TABLE: | |
Ref: ConnectionTable | |
# IAM roles are defined for the entire service. | |
# Implementing zero trust roles per Lambda can be | |
# done with manual CloudFormation. | |
iam: | |
role: | |
statements: | |
- Effect: Allow | |
Action: | |
- dynamodb:Query | |
- dynamodb:GetItem | |
- dynamodb:PutItem | |
- dynamodb:DeleteItem | |
- dynamodb:Scan | |
Resource: | |
Fn::GetAtt: [ ConnectionTable, Arn ] | |
package: | |
patterns: | |
- '!./**' | |
- ./bin/** | |
functions: | |
connect: | |
# Go binary will be output here | |
handler: bin/connect | |
events: | |
- websocket: | |
# Predefined $connect route will | |
# be integrated with this function | |
route: $connect | |
resources: | |
# Raw CloudFormation can be added here | |
Resources: | |
# This is the definition of the DynamoDB table for | |
# storing references to active WebSocket connections. | |
ConnectionTable: | |
Type: AWS::DynamoDB::Table | |
Properties: | |
TableName: sls-chat-app-connections | |
# We only need to define the key here, and can | |
# freely manage other attributes in the application | |
# layer due to the NoSQL nature of DynamoDB. | |
AttributeDefinitions: | |
- AttributeName: connection_id | |
AttributeType: S | |
KeySchema: | |
- AttributeName: connection_id | |
KeyType: HASH | |
# PAY_PER_REQUEST sets on-demand pricing | |
BillingMode: PAY_PER_REQUEST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment