Created
January 7, 2019 22:56
-
-
Save robzhu/4b9474601d71cd02561c6a0777403de1 to your computer and use it in GitHub Desktop.
Lambda code for the echo route
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the purpose of the patch.js file and is it still needed today in your opinion?