Steven Talafous
Steven Talafous

Reputation: 107

Trying to make a publicly accessible AWS Cloud9 URL

I'm using AWS Cloud9 and it's been smooth sailing, but now I'm trying to make my URL public so that I can make HTTP requests in Postman, and I'm really struggling. I'm very much a beginner full stack developer and any help would be appreciated.

Thanks, Steven

I'm trying to properly follow this guide:

https://docs.aws.amazon.com/cloud9/latest/user-guide/app-preview.html

Specifically, I make it to Step 4 where it asks me to change the IP address in my code. When I change my Node JS Express app's app.listen IP address to my EC2 instance IP address, I get an error.

I think I've successfully made my EC2 instance publicly accessible and that it's just my code that is not listening correctly (those steps seemed easy to follow, but I could be wrong.

var express = require("express");
var app = express();

app.set("view engine", "ejs"); 

app.get("/", function (req, res){
    res.render("helloWorld");
});


app.listen(8080, '**AWS EC2 instance IP**', function(){
    console.log("Server Has Started!");
});

It runs fine when I do not specify an IP address in the app.listen, but then of course I can only access the server from a different tab in the same browser. Here is what the console spits out when I run the code with the AWS EC2 instance IP included:

events.js:174

      throw er; // Unhandled 'error' event

      ^



Error: listen EADDRNOTAVAIL: address not available **AWS EC2 instance IP**:8080

    at Server.setupListenHandle [as _listen2] (net.js:1262:19)

    at listenInCluster (net.js:1327:12)

    at doListen (net.js:1460:7)

    at process._tickCallback (internal/process/next_tick.js:63:19)

    at Function.Module.runMain (internal/modules/cjs/loader.js:832:11)

    at startup (internal/bootstrap/node.js:283:19)

    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Emitted 'error' event at:

    at emitErrorNT (net.js:1306:8)

    at process._tickCallback (internal/process/next_tick.js:63:19)

    [... lines matching original stack trace ...]

    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Upvotes: 0

Views: 3254

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179364

EC2 instances do not have their public IP bound to the IP stack. Translation from the public IP to the instance's private IP is handled automatically by the Internet Gateway.

Specifying the instance's private IP is what you actually need to do, even though it may not be intuitive that this is correct. Or, as the guide indicates, use 0.0.0.0 which means "all interfaces."

Upvotes: 2

Related Questions