To keep it very simple, For any two programs to communicate with each other over a network, you need two things
- IP Address
- Port Number
Consider you have two EC2 instances. Lets name them
- Instance1
- 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:-
- Program1 (program running on Instance1), running on port 1000
- Program2 (program running on Instance2), running on port 2000
Let us first talk about Program1 running on port 1000 of Instance1.
- Log onto AWS Console
- Click on EC2 Service
- In the left panel, click on Security Groups
- Click on the button Create Security Group
- An overlay will open.
- Put-in the name and description of your choosing
- Click on the tab Inbound and click on Add Rule
- Here, you are adding which port should accept connections.
- 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"
- Click on the tab Outbound and click on Add Rule
- Repeat Step 9, if you want outbound communication.
Repeat these steps on Instance2 and you will be good to go.