@@ -41,6 +41,8 @@ yarn add laravel-echo-api-gateway
41
41
npn install --save laravel-echo-api-gateway
42
42
```
43
43
44
+ ### When using Bref
45
+
44
46
Next, when using Bref, we have to add some elements to our ` serverless.yml ` file. If using Vapor, these resources have
45
47
to be created by hand using the AWS CLI or console.
46
48
@@ -116,8 +118,11 @@ provider:
116
118
name: aws
117
119
118
120
environment:
119
- # Add this line
120
- BROADCAST_API_GATEWAY_URL: !Join [ '', [ 'wss://', !Ref "WebsocketsApi", '.execute-api.', "${self:provider.region}", '.', !Ref "AWS::URLSuffix", '/', "${self:provider.stage}" ] ]
121
+ # Add these variables
122
+ BROADCAST_DRIVER: laravel-echo-api-gateway
123
+ LARAVEL_ECHO_API_GATEWAY_DYNAMODB_TABLE: !Ref ConnectionsTable
124
+ LARAVEL_ECHO_API_GATEWAY_API_ID: !Ref WebsocketsApi
125
+ LARAVEL_ECHO_API_GATEWAY_API_STAGE: "${self:provider.stage}"
121
126
` ` `
122
127
123
128
Next, create the PHP handler file in `handlers/websocket.php`
@@ -139,13 +144,47 @@ $kernel->bootstrap();
139
144
return $app->make(Handler::class);
140
145
` ` `
141
146
147
+ Now, deploy your app by running `serverless deploy` or similar. Write down the websocket url the output gives you.
148
+
149
+ # ## When using Vapor
150
+
151
+ When using Vapor, you will have to create these required resources by hand using the AWS CLI or Console :
152
+
153
+ # ### DynamoDB table for connections
154
+
155
+ Create a DynamoDB table for the connections. Use `connectionId` (string) as a HASH key, and `channel` (string) as a SORT
156
+ key. Set the capacity setting to whatever you like (probably on-demand).
157
+
158
+ Create 2 indexes :
159
+
160
+ 1. Name : ` lookup-by-connection` , key: `connectionId`, no sort key, projected: ALL
161
+ 2. Name : ` lookup-by-channel` , key: `channel`, no sort key, projected: ALL
162
+
163
+ # ### API Gateway
164
+
165
+ Create a new Websocket API. Enter a name and leave the route selection expression to what it is. Add a `$disconnect`
166
+ and `$default`. Set both integrations to `Lambda` and select your CLI lambda from the list. Set the name of the stage to
167
+ what you desire and create the API. Once created, write down the ID, as we'll need it later.
168
+
169
+ # ### IAM Permissions
170
+
171
+ In IAM, go to roles and open `laravel-vapor-role`. Open the inline policy and edit it. On the JSON tab,
172
+ add `"execute-api:*"` to the list of actions.
173
+
174
+ Then, login to [Laravel Vapor](https://vapor.laravel.com/app), go to team settings, AWS Accounts, click on Role next to
175
+ the correct account and deselect Receive Updates.
176
+
142
177
Edit your `.env` :
143
178
144
179
` ` ` dotenv
145
180
BROADCAST_DRIVER=laravel-echo-api-gateway
146
- MIX_BROADCAST_API_GATEWAY_URL="${BROADCAST_API_GATEWAY_URL}"
181
+ LARAVEL_ECHO_API_GATEWAY_DYNAMODB_TABLE=the-table-name-you-entered-when-creating-it
182
+ LARAVEL_ECHO_API_GATEWAY_API_ID=your-websocket-api-id
183
+ LARAVEL_ECHO_API_GATEWAY_API_STAGE=your-api-stage-name
147
184
` ` `
148
185
186
+ # ## For both Bref and Vapor
187
+
149
188
Add to your javascript file :
150
189
151
190
` ` ` js
@@ -154,7 +193,8 @@ import {broadcaster} from 'laravel-echo-api-gateway';
154
193
155
194
const echo = new Echo({
156
195
broadcaster,
157
- host: process.env.MIX_BROADCAST_API_GATEWAY_URL,
196
+ // replace the placeholders
197
+ host: 'wss://{api-ip}.execute-api.{region}.amazonaws.com/{stage}',
158
198
});
159
199
` ` `
160
200
0 commit comments