我正在使用AWS构建无服务器应用程序。我要构建的过程是这样的:
该应用程序还能够向其他已连接的客户端广播某些消息,但是事实已经解决了,这就是为什么您可以看到一些聊天引用的原因。
到目前为止,我拥有将客户端连接到套接字的所有逻辑,但是我仍然需要将端点(A)连接到Websocket(B)。
我的YAML文件是这样的:
org: jons2019
app: myapp
service: websockets-chat
provider:
name: aws
runtime: nodejs8.10
iamRoleStatements:
- Effect: Allow
Action:
- "dynamodb:PutItem"
- "dynamodb:GetItem"
- "dynamodb:DeleteItem"
- "dynamodb:Scan"
Resource:
- Fn::GetAtt: [ChatTable, Arn]
- Effect: Allow
Action:
- "execute-api:ManageConnections"
Resource:
- "arn:aws:execute-api:*:*:**/@connections/*"
functions:
connectionHandler:
handler: handler.connectionHandler
events:
- websocket:
route: $connect
- websocket:
route: $disconnect
defaultHandler:
handler: handler.defaultHandler
events:
- websocket:
route: $default
sendMessageHandler:
handler: handler.sendMessageHandler
events:
- websocket:
route: sendMessage
resources:
Resources:
ChatTable:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
- AttributeName: "connectionId"
AttributeType: "S"
KeySchema:
- AttributeName: "connectionId"
KeyType: "HASH"
BillingMode: PAY_PER_REQUEST
TableName: chatIdTable
AnotherResource that creates an API endpoint with a Lambda function with proper permissions to write to the websocket.
我是无服务器新手,我想拥有合适的新资源,使我可以创建一个新端点,该端点将接收请求,并具有向已连接到Websocket的给定客户端发送消息的权限。