亚马逊AWS EC2 GoLang

I have a small Go web server which I have deployed on Amazon Web Services but I am having trouble getting to work.

My EC2 instance has both public & private IP addresses assigned, but I am unable to start the Go server.

If I serve it on localhost it works, but obviously I can't connect to it, so I am trying to assign it the public ip, but it crashes without throwing any errors.

http.ListenAndServe("public_ip", nil)

Any ideas how to proceed from here?

I'm not sure what does it mean that your server crashes without throwing any errors. Make sure you're logging the error:

log.Println(http.ListenAndServe(addr, nil))

This should give you some idea why it doesn't work. Anything there?

For example, when running on port < 1024 without root privileges, I can see:

2014/11/25 19:14:51 listen tcp :80: bind: permission denied

Now, if you run the server on address :8080, you should be listening on all the interfaces. You can test the server from the local host. If it works, make sure your machine is reachable from the Internet on this port by modifying security group for your instance.

If it still doesn't work, please let us know what does and a little bit more about the crash.

A couple things to check:

  • Your public IP does not exist at the local machine (it is NATed), listen for the private address or 0.0.0.0 for all.
  • If it is connecting from localhost but not remotely, make sure:

    • That the instance's security group has an inbound rule allowing the port and source.
    • If it is on a VPC, that the VPC is attached to an Internet Gateway and there is a route to it.