Skip to content

Instantly share code, notes, and snippets.

@robzhu
Created January 7, 2019 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robzhu/4b9474601d71cd02561c6a0777403de1 to your computer and use it in GitHub Desktop.
Save robzhu/4b9474601d71cd02561c6a0777403de1 to your computer and use it in GitHub Desktop.
Lambda code for the echo route
const AWS = require('aws-sdk');
// apply the patch
require('./patch.js');
let send = undefined;
function init(event) {
const apigwManagementApi = new AWS.ApiGatewayManagementApi({
apiVersion: '2018-11-29',
endpoint: event.requestContext.domainName + '/' + event.requestContext.stage
});
send = async (connectionId, data) => {
await apigwManagementApi.postToConnection({ ConnectionId: connectionId, Data: `Echo: ${data}` }).promise();
}
}
exports.handler = async(event) => {
init(event);
const connectionId = event.requestContext.connectionId;
let data = JSON.parse(event.body).data
await send(connectionId, data);
// the return value is ignored when this function is invoked from WebSocket gateway
return {};
};
@Dzhuneyt
Copy link

What is the purpose of the patch.js file and is it still needed today in your opinion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment