我在尝试为 WebSocket API 设置 lambda 授权时遇到问题。
无服务器.yml
functions:
sample-web-socket-authorizer:
iamRoleStatementsName: stack-${opt:stage}-web-socket-authorizer
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- 'cognito-idp:*'
Resource: '*'
handler: sample-web-socket-authorizer/handler.handler
environment:
JWK_URL: ${self:custom.jwkUrl}
CLIENT_ID: ${self:custom.cognitoClientId}
...
connectionHandler:
handler: handler.connectionHandler
events:
- websocket:
route: $connect
authorizer:
name: sample-web-socket-authorizer
identitySource:
- 'route.request.querystring.Authorizer'
在前端,我想发送一个 tokenId 或 accessToken 以在授权者中使用
wss://abcd1234.execute-api.ap-region-1.amazonaws.com/pre?Authorizer=${token}
你们可以给我一个示例代码,使用 python 为我的 websocket api 创建一个 lambda 授权器。