service: chromedriver
provider:
name: aws
ecr:
images:
chromedriver:
path: ./
functions:
chromedriver:
image:
name: chromedriver
events:
- websocket: $connect
- websocket: $disconnect
- websocket:
route: $default
routeResponseSelectionExpression: $default
You can see an example of the Dockerfile at https://bref.sh/docs/web-apps/docker.html , mine is the same as the example except it also adds Chrome and Chromedriver. Here's the handler PHP:
<?php
use Bref\Context\Context;
use Bref\Event\ApiGateway\WebsocketEvent;
use Bref\Event\ApiGateway\WebsocketHandler;
use Bref\Event\Http\HttpResponse;
require __DIR__ . '/vendor/autoload.php';
class Handler extends WebsocketHandler {
public function handleWebsocket(WebsocketEvent $event, Context $context): HttpResponse {
switch ($event->getEventType()) {
case 'CONNECT':
file_put_contents('/tmp/log.txt', $event->getConnectionId());
break;
}
return new HttpResponse(@file_get_contents('/tmp/log.txt') ?: 'not found');
}
}
return new Handler();
Testing this:
wscat --connect wss://url.from.the.output.of.serverless.deploy/dev
Connected (press CTRL+C to quit)
> test
< fd4xBe7HIAMCK9A=
> test
< fd4xBe7HIAMCK9A=
Same connection ID both times. As far as I understand -- and that's not too far -- this is probably just a "warm start" of Lambda but that is sufficient for my purposes.