Marsellus Wallace
Marsellus Wallace

Reputation: 18611

How to connect to a webserver on ec2 'privately'

I have a little web application deployed on an ec2 instance and I'd like to test it without making it publicly available.

Using an elastic IP does not solve my issue because the IP would then expose it to the outside world and we are not ready for this yet.

I'm aware of Amazon VPC but it seems a bit overkill since I don't need all those functionalities and I don't want to deal with the set up. All I need is to be able to hit the webserver by using a private IP or something like that.

Is there a quick and dirty solution for this?

Upvotes: 4

Views: 4845

Answers (4)

Ryan Parman
Ryan Parman

Reputation: 6945

If you want an EC2 instance that is truly private, you need to look at launching it inside of a VPC. You'll want a Bastion Host in your public subnet and your instance in the private subnet.

Upvotes: 0

Barak
Barak

Reputation: 3066

Create a security group that only allows traffic from your IP (the IP of the machine running the browser where you will do the testing) to the web server port (80, probably) and assign this security group to your ec2 instance.

This way only you can access the web app.

If you need to work from different locations, write a simple script to update the security group and add your current IP. These changes are applied immediately and do not require a restart. You can grab your current IP from whatismyip and use the Amazon SDK to update the security group.

Upvotes: 2

Greg Kempe
Greg Kempe

Reputation: 1937

You could setup your web server to listen only on 127.0.0.1 (rather than 0.0.0.0) and then use SSH to tunnel a connection from your local machine to the instance.

From your desktop, setup the SSH connection:

$ ssh -L 3000:localhost:80 [email protected]

Then visit http://localhost:3000 in your browser and it will forward port 3000 on your desktop to port 80 on the instance, via the SSH connection.

Upvotes: 10

Assaf Lavie
Assaf Lavie

Reputation: 76103

You don't need an EIP to access your instance - it has a public DNS name associated with it automatically.

Upvotes: 1

Related Questions