How do I do an HTTP POST to a server living in an Amazon ec2 instance over ssh?

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

Posted 2018-10-17T14:06:44.460

Reputation: 101

1Thanks for the help Attie, yes that's what I meant – anon – 2018-10-17T14:08:50.387

"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 – 2018-10-17T14:08:54.143

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 – 2018-10-17T14:10:33.057

I presume you are able to use SSH? Have you tried using curl with the same IP you used for SSH? – Attie – 2018-10-17T14:11:15.740

No, could you provide an example attie? – anon – 2018-10-17T14:12:00.703

How are you managing the EC2 instance? SSH? – Attie – 2018-10-17T14:12:27.697

Possible duplicate of What is the cURL command-line syntax to do a POST request?

– Ahmed Ashour – 2018-10-17T14:19:19.823

Its different because I would like to do it over ssh – anon – 2018-10-17T14:24:10.800

Answers

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

Posted 2018-10-17T14:06:44.460

Reputation: 14 841

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 – 2018-10-17T14:47:14.083

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 – 2018-10-17T15:45:08.067

This link might help: Authorizing Inbound Traffic for Your Linux Instances

– Attie – 2018-10-17T15:45:26.947