My current serverless.yaml file is as follows:
service: StockWave
frameworkVersion: '3'
plugins:
- serverless-plugin-typescript
provider:
name: aws
runtime: nodejs16.x
stage: ${opt:stage, 'dev'}
environment:
WEBSOCKET_API_URL: !Join [ '', [ 'https://', !Ref WebsocketApi, '.execute-api.',!Ref 'AWS::Region','.amazonaws.com/dev'] ]
functions:
getStockData:
handler: handler.getStockData
role: arn:aws:iam::809131133799:role/LabRole
description: Get stock data
events:
- http:
path: /stock-data
method: get
cors: true
request:
parameters:
querystrings:
symbol: true
limit: false
getSentiments:
handler: handler.getSentiments
role: arn:aws:iam::809131133799:role/LabRole
description: Get sentiments
events:
- http:
path: /sentiments
method: get
cors: true
connect:
handler: handler.connect
role: arn:aws:iam::809131133799:role/LabRole
description: Connect to websocket
events:
- websocket:
route: $connect
disconnect:
handler: handler.disconnect
role: arn:aws:iam::809131133799:role/LabRole
description: Disconnect from websocket
events:
- websocket:
route: $disconnect
sendMessage:
handler: handler.sendMessage
role: arn:aws:iam::809131133799:role/LabRole
description: Send data to websocket
events:
- websocket:
route: sendMessage
resources:
Resources:
WebsocketApi:
Type: AWS::ApiGatewayV2::Api
Properties:
Name: WebsocketApi
ProtocolType: WEBSOCKET
RouteSelectionExpression: "$request.body.action"
However, this creates two WebSocket APIs, which is not what I want. How can I specify that my WebSocket Lambda functions should use the WebsocketApi
resource?