Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created October 20, 2021 10:31
Show Gist options
  • Save velotiotech/9740a04578742b4603476ef94b2e5793 to your computer and use it in GitHub Desktop.
Save velotiotech/9740a04578742b4603476ef94b2e5793 to your computer and use it in GitHub Desktop.
console.log(`Received socket connectionId: ${event.requestContext && event.requestContext.connectionId}`);
if (!(event.requestContext && event.requestContext.connectionId)) {
throw new Error('Invalid event. Missing `connectionId` parameter.');
}
const connectionId = event.requestContext.connectionId;
const route = event.requestContext.routeKey;
console.log(`data from ${connectionId} ${event.body}`);
const connection = new Client(connectionId);
const response = { statusCode: 200, body: '' };
if (route === '$connect') {
console.log(`Route ${route} - Socket connectionId connectedconected: ${event.requestContext && event.requestContext.connectionId}`);
await new Client(connectionId).connect();
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment