Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect two Ec2 Instance so that they can Communicate with each other [closed]

I want to connect two EC2 instances with each other so that they can communicate with each other.

One will have Wordpress installed, and the 2nd will have a database configured (e.g. Mysql/Mariadb).

I found the problem in the way we can connect 2 EC2 instances with each other by using private IP.

like image 229
Rishabh Bahukhandi Avatar asked May 19 '16 10:05

Rishabh Bahukhandi


People also ask

How do you establish connection between EC2 instance to another EC2 instance?

To connect from the Amazon EC2 consoleOpen the Amazon EC2 console. In the left navigation pane, choose Instances and select the instance to which to connect. Choose Connect. On the Connect To Your Instance page, choose EC2 Instance Connect (browser-based SSH connection), Connect.


1 Answers

To keep it very simple, For any two programs to communicate with each other over a network, you need two things

  1. IP Address
  2. Port Number

Consider you have two EC2 instances. Lets name them

  1. Instance1
  2. Instance2

On each of these instances, you must be having some programs between which you want the communication to take place. Also, these programs must be running on a PORT of the instance. For example, tomcat instance runs on port 8080 by default. Lets name our programs:-

  1. Program1 (program running on Instance1), running on port 1000
  2. Program2 (program running on Instance2), running on port 2000

Let us first talk about Program1 running on port 1000 of Instance1.

  1. Log onto AWS Console
  2. Click on EC2 Service
  3. In the left panel, click on Security Groups
  4. Click on the button Create Security Group
  5. An overlay will open.
  6. Put-in the name and description of your choosing
  7. Click on the tab Inbound and click on Add Rule
  8. Here, you are adding which port should accept connections.
  9. Set the following details:-

    -Type: Custom TCP Rule
    -Protocol: TCP
    -Port Range: 1000 [Or any other port on which your program runs]
    -Source: External IP from where Program1 can be accessed. It can be "Everywhere", "My IP" or a "Custom IP"
  10. Click on the tab Outbound and click on Add Rule
  11. Repeat Step 9, if you want outbound communication.

Repeat these steps on Instance2 and you will be good to go.

like image 115
Monis Avatar answered Sep 23 '22 20:09

Monis