Last active
August 10, 2016 22:32
-
-
Save wearhere/b4b3671c56ec799cdf089d5fa6587542 to your computer and use it in GitHub Desktop.
Pseudocode for achieving sticky websockets on AWS using per-instance EIPs vended over HTTP.
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
function connect() { | |
// Since we'd have sticky HTTP sessions, this will always go to the same instance, | |
// thus the websocket will connect to the same instance, assuming it's still living. | |
$.get('/websocket') | |
.then(function(ipAddress) { | |
Websocket.connect(ipAddress); | |
}); | |
} | |
Websocket.on('disconnection', connect); |
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
// Not sure if this could be an environment variable or would have to be fetched | |
// like instance metadata. | |
var MY_EIP; | |
app.get('/websocket', function(req, res) { | |
res.send(MY_EIP); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment