uppy: serverless example not working
I tried deploying the example exactly as it, but when I try to upload my instagram photo the wss connection is immediately terminated and I see no upload progress. I don’t think lambda can support wss connections?
Here is the error:
WebSocket connection to 'wss://m6g8yvhwt1.execute-api.us-east-1.amazonaws.com/development/api/7a20ec32-7504-477d-9781-e6c60bdc1d80' failed: Connection closed before receiving a handshake response
Has anyone been able to get this to work?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (8 by maintainers)
Commits related to this issue
- Remove Serverless example Because it doesn't work well. and we don't have the resources to make it work well. Community PRs welcome to patch this up! Until then, let's not confuse any more users. ht... — committed to transloadit/uppy by kvz 4 years ago
- Remove Serverless example Because it doesn't work well. and we don't have the resources to make it work well. Community PRs welcome to patch this up! Until then, let's not confuse any more users. ht... — committed to docsend/uppy by kvz 4 years ago
I see, we added the serverless example as a courtesy but it seems to be a source of ongoing issues and a bit of a timesink for our engineers. With finite resources and no use for it on our part, I can’t really justify that we keep debugging this example. I’m happy to accept community contributions to patch this up, but until then I think we’d better deprecate and remove this example from our repo. Thoughts @arturi ?
I’ve investigated this and found that while API Gateway does support websockets, it does not support proxying all matching URLs the same way that HTTP Lambda Proxies do.
API Gateway websockets expect one of four events:
$connect$disconnect$defaultThe problem seems to be that even if you get the websocket support into serverless.yml:
…this will still not correctly route the websocket connection correctly, as the Uppy client attempts to connect to
wss://{host}/api/{token}, when API Gateway is expecting a connection onwss://{host}, with thetokenprovided in the JSON payload of the websocket message.I don’t think there’s a super simple solution to this. The
@uppy/aws-s3-multipartplugin would need to change where it connects to the socket URL to connect just to the host, not to a custom path. This code is also in the@uppy/tuspackage and the@uppy/xhr-uploadpackage. Probably an appropriate change would be to connect with the token as a parameter, rather than as part of the URL. I believe Uppy uses Socket.io to provide websocket connectivity, so I think parameters can be provided in the call toconnect.The companion code would also need to change. It currently extracts the token from the fullpath of the websocket URL, and it would instead need to fetch the token from the response URL.
The companion change could probably retain backwards compatibility by looking for the token both in the connection payload parameters, and by extracting from the URL. I’m not so sure that the client code could remain compatible with an older version of
@uppy/companionthough.Interestingly, I have not yet found a dependency on sockets existing in the normal
@uppy/aws-s3plugin. I am currently experimenting with the use of this plugin to see if it works with a serverless-deployed companion instance, and will report back here if I have any luck.@kvz I don’t think it’s solved, the example runs < 1.0 @uppy/companion package, and seems not to work with default configuration. In particular:
ServiceEndpoint: https://tgt7qn1t68.execute-api.eu-west-1.amazonaws.com/dev ServiceEndpointWebsocket: wss://7jneezqms3.execute-api.eu-west-1.amazonaws.com/dev@kiloreux @superandrew213 I am facing the same issue with companion + API Gateway + AWS Lambda. Despite trying to add the websocket event in the serverless declaration, I keep getting the wss socket error; with the difference that the error is thrown during handshake.
Is there any update on this? Thanks for your help.