0

I have a server listening on http://0.0.0.0:8000, however this is living in an Amazon instance.

How can I make an HTTP POST request from an external computer (using curl)? That is, I would like to use the server listening as an API. This is different from other cases because I would like to do it over ssh.

anon
  • 101
  • 2
  • 1
    Thanks for the help Attie, yes that's what I meant – anon Oct 17 '18 at 14:08
  • "_listening on `0.0.0.0:8000`_" means "_listening on all interfaces_" - so can you communicate with it on it's public IP? (the same you would use for SSH) – Attie Oct 17 '18 at 14:08
  • Yes I think so Attie, when I start the server it just says: `no port specified, defaulting to port 8000` that lives in the ec2 instance. I would like to do the `curl -XPOST` from an "external machine" – anon Oct 17 '18 at 14:10
  • I presume you are able to use SSH? Have you tried using `curl` with the same IP you used for SSH? – Attie Oct 17 '18 at 14:11
  • No, could you provide an example attie? – anon Oct 17 '18 at 14:12
  • How are you managing the EC2 instance? SSH? – Attie Oct 17 '18 at 14:12
  • Possible duplicate of [What is the cURL command-line syntax to do a POST request?](https://superuser.com/questions/149329/what-is-the-curl-command-line-syntax-to-do-a-post-request) – Ahmed Ashour Oct 17 '18 at 14:19
  • Its different because I would like to do it over ssh – anon Oct 17 '18 at 14:24

1 Answers1

0

If you want to run curl on the EC2 instance, and tunnel the output via ssh, then try the following:

ssh ${USERNAME}@${EC2_INSTANCE_IP} curl -s http://localhost:8000/

You should see the result directly on the terminal (-s will inhibit curl's output).

You can run any command like this, there's nothing special for curl.

If this works, then you can alter the curl parameters to use -X POST and/or -d, along with the correct endpoint.


Please remember though, that 0.0.0.0 is a "special" address that actually means "listening on all interfaces"... So unless you configure the inbound rules correctly, anyone can still do curl http://${EC2_INSTANCE_IP}:8000/ and hit your server.

Attie
  • 19,231
  • 5
  • 58
  • 73
  • Do you have a reference on how to configure this on the amazon instance? I got a Failed to connect to the instance, timed out – anon Oct 17 '18 at 14:47
  • You might like to ask another question, specifically around inbound rules for EC2... get the basic SSH working first, and then come back and try to "_use `curl` over SSH_" afterwards. – Attie Oct 17 '18 at 15:45
  • This link might help: [Authorizing Inbound Traffic for Your Linux Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/authorizing-access-to-an-instance.html) – Attie Oct 17 '18 at 15:45