AWS VPC Peering - Step By Step Tutorial (Part-12) | #aws #vpc #devops #cloud #programming #coding

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to the session on AWS VPC pairing by the end of this session you will know how to set up your VPC pairing between the two vpcs and also you will know like what are the benefits of using the VPC pairing let's start with it so here you can see onto the screen so first of all this is our AWS account on which we are going to set up this whole demo so we are going to create two vpcs on the left hand side you will find a test VPC 1 and on the right hand side you will find a test VPC to these two vpcs are separated with each other and here inside that VPC we are going to create subnet and inside the subnet we are going to provision and Linux machine which is going to be our ec2 machine and similarly on the other VPC which is a VPC 2 where also we are going to create our subnet and ec2 instance and after that we are going to set up a VPC peing so here you can see a purple icon for a VPC peering and once we set up this VPC peing then this ec2 instance from test vpc1 will be able to communicate with our test instance present inside our VPC 2 here is my AWS console so let's start first creating the VPC so in the search box type VPC click on VPC and here you will find option to create VPC so click on it and here you will find options to create a VPC so first of all select the VPC only we just want to create a VPC and here we can put the name like a test VPC 1 uh CER range so this is going to be the IP range which we are going to allow inside our VPC so I'm just going to put 12. 0.0.0 sl16 so which means I will have around 65,000 possible IP add addresses within my VPC tency I'm just going to stick with default and I'm just going to click on create VPC so this is going to be my first VPC and similarly I'm just going to create a one more VPC uh like test VPC 2 so click over here so I'm just going to enter the name test VPC 2 and here I'm just going to enter The Cider range so here I'm just going to change 13 instead of 12 so that ident I can identify the IP ranges between those two vpcs and after that I'm just going to click on create VPC and check if whether you have created those VPC so here you can see our both the test VPC 1 and test VPC 2 has been created now after creating the VPC the next thing which we need to create is the route table so we are going to create a two route table one for test vpc1 and test VPC 2 so that it can route the traffic to our particular subnet so let's go back to our AWS console and here in the VPC dasboard on the left hand side you will find a route table over here so here there are few route tables which has already been created but we are going to create our own new Fresh Route tables so click on this create route table over here so I'm just going to put test RT for Route table uh for VPC 1 and here we need to select the VPC so I'm just going to attach this route table to VPC 1 and after that click on Route table I'm just going to copy the name uh and click on create route table so this is the route table which we have created I'm just going to create a one more route table for VPC 2 so again click on create route table I have already copied the name so I'm just going to change it to two and select the VPC so here I'm just going to select the VPC 2 and after that just click on create route table now after creating the VPC route table the next thing which we need to create is the subnet so we are going to create two subnet both in VPC 1 and VPC 2 so here is my VPC dashboard onto my AWS console so click onto the VPC dashboard over here and here on the left hand side you can also find the option for creating the subnet so click on this subnet and here you will find the default subnet but we are not going to use those on so click on create subnet H select the VPC so first of all I'm just going to create a subnet for our test VPC 1 so C select this one and here I'm just going to put the name so I'm just going to put test subnet VPC 1 and I'm just going to put one a for availability zone so here I will explain like what's the availability zone is so here you need to choose like I'm just going to choose Europe Central 1 a but select whatever uh closest reasons nearby you all right so I have created this subnet and and the IP ranges I just need to put in so I will just copy this IP address range from from from my VPC and I'm just going to put over here and I'm just going to change it to 1 and here I'm just going to put it to 24 so here you can see now 256 IP addresses are possible within my Subnet this is a demo that's why I'm just keeping the bare minimum things over here all right so now we have created this uh first Subnet I'm just going to copy it because I will need it for creating another subnet so I'm just going to click on create subnet now and now you can see our test subnet has been created for VPC 1 I'm just going to create one more subnet and select the VPC so this time I'm just going to choose VPC 2 uh subnet name so I'm just going to put in so I will just change it to two and I'll keep it 1 a so because the availability zone I'm using it 1 a uh this is a demo that's why I'm creating only one subnet but in your actual uh project or actual application you might need to create multiple subnet for multiple availab zone so that just keep in mind all right so now I have created those so I just need to specify the IP range for my Subnet so I'm just going to copy that range and here I'm just going to suffix it with one and here I'm just going to choose 24 all right so just click on create subnet now and I'll just remove this filter over here so here you can see our both the subnet has been created I'm just going to put test and hit enter so here you can see our I'll just remove it anyway so we are having two subnets now which is for VPC 1 and as well as for VPC 2 all right the next thing which we need to do is we need to associate our route table with our subnet so we have created the route table we have created the subnet but both are in a detached mode so we need to associate both route table and the subnet so for that let's go back to our AWS console and here uh just click on VPC go to the route tables and here you can see our uh route table for vpc1 and VPC 2 so I'm just going to select the first one uh go to subnet Association click on edit subnet and here you can choose the subnet for VPC 1 and click on Save Association so now our uh I'll check the diagram once again so now our root table has been associated with this particular subnet but also in the root table we need to Grant the internet access and for that we need a internet gateway so what we will do we'll just go over here and here we are having option for internet gateway and here we are going to create a new internet Gateway so I'll just put uh test internet gateway for VPC 1 uh click on create internet gateway and now our internet gateway has been created but this internet gateway is not associated with our VPC so for that we need to attach the VPC so here as you can see the name we have put it is for VPC 1 so in the actions go to attach VPC select the VPC and select vpc1 and attach internet gateway all right so let's take a look onto the diagram once again so now we have the route table associated with subnet and now we have created the internet gateway for this particular VPC and now we in the route table we need to create a route for internet using the internet gateway so that this subnet can be uh any resource inside this subnet can be accessed from internet although I have mentioned this is as a private subnet but this is going to be our public subnet so that's a correction I would like to make it over here all right so let's go back to our AWS console and here this is a internet gateway and go to Route table now and open the route table over here and as you can see our subnet has already been Associated go to routes now go to edit routes and here eight routes so here we will choose uh access from anywhere so that's why I'm just going to choose this IP address and from the drop down choose internet gateway and here you will find the test internet gateway which we have just created click on it and click save changes all right so now we are done with the VPC one where we have uh let's take your diagram one where we have VPC route table uh subnet and Route table is attached with subnet and also internet gway has been attached to VPC as well as we have created a route table a route entry inside my route table and the same thing I'm just going to perform onto the VPC 2 also so for that let's first create the internet gateway so go over here I'll just copy this name from here because I'm just going to keep the similar name so click here for VPC 2 and uh yeah just click on create internet gateway and now internet gway has been created but we need to attach it so click on attach attach to VPC and here select the VPC so this is our test VPC 2 for that and click on attach internet gateway all right so internet gateway has been attached so let's go to the route table and check the association so this is our VPC uh two route table click on this route table ID click on first the submit Association so here you can see there is no subnet associat so click on edit subnet uh select the subnet click on Save Association so now subnet has been Associated now we need to make a internet route entry inside this uh route table so click on edit routes add routes so here I'll choose anywhere from anywhere so this is the IP address for that select the internet gateway and here test VPC 2 internet gateway so select that one and click on Save changes all right so now our uh Network part is almost done and now we need to provision the ec2 instance in both the VPC so I'll just go to ec2 dashboard and I'll just provision the ec2 instances okay so go to your homepage of your ads console over here and in the search box type ec2 Click On ec2 and Here click on launch instances and here first of all we need to enter the name so I will put vpc1 ec2 instance and after that I just need to choose the image I'm just going to choose UB 2 as my image and the instance type t2. micro I'm just going to stick with that one and here we need to next thing which we need to do is to enter the key paay login so I'll just create a new key payer over here so click on create new key payer type in the VPC 1 ec2 key so this is the name I'm just going to keep it so I'll just copy this name just in case create a key pair and here you can see I have downloaded the private key with me and the public Keys has been associated with my instance all right in the network setting now we need to attach to our VPC which we have created so I just want this ec2 be attached with my vpc1 so I'll just from the drop down choose vpc1 and here in the subnet you can see the subnet which we have created which is already selected uh Auto assign public IP so I just wanted to enable it because I just wanted to do the SSH into it all right the firewall Security Group so here we have some Security Group already so SSH Security Group is already there on a port 22 so which I wanted I just wanted to have a one more Security Group for HTTP request so that we can access the homepage of Apache which we are going to install it so here it is on a running on a we are allowing the portet actually and here I'll just choose from anywhere all right so now security groups are done so we have added for Port 22 as well as for Port 80 after that uh I'll just skip the advanced network setting I'll just stick with default the storage I want to have it 8 gigs and in the advanced detail we need to have the script in the user data section to install the Apache as a application inside my ec2 instance so go over here here you will find a user data section so I'll just copy uh script from my notepad so just give me a minute so here I'll just copy this script and paste it over here so what will happen this user data section uh it will just going to install the Apache when this is going to boot up my ec2 install so that's the purpose of this user data script so here it is updating the package manager here it is installing the Apache and then here it is going to in uh update the homepage of uh my Apache 2 with host name and then it is going to restart the Apache 2 it's that simple all right so let's click on launch instance and it might take a couple of minute to start so I'll be back once it's ready so here you can see the instance is in success all right so here you can see my ec2 instance is running under my vpc1 so I'll just click on this instance ID copy this public IP address I'll just paste over here to verify that I have installed my Apache uh in Apache server or not so here you can see my Apache has been installed and this is the host IP but for VPC pairing we are going to do the SSH and then we are just going to check a few more things later in this session so before that I'll just close this one we just need to spin another E2 instance so if you take a look onto the diagram once again so here we have set up this ec2 instance which is running and now we need to set up this ec2 instance as well so let's go back to our ec2 dashboard so all the steps are pretty much same the only thing I will change over here is to set up the different VPC 2 so launch instances and here I'll just copy the name from my ec2 dashboard so that I have a similar name over here so this is the name so I'm just going to copy and change it to two all right so now the name has been changed select ub2 uh ub2 as my base operating system t2. micro that's fine and here I would like to create a new key pair so I will just check the name vpc1 ec2 key so I'm just going to choose VPC 2 and what's the name of it here is the downloaded key so from here I'm looking into the name so ec2 key key uh that should be good I guess and then click on create key paer so now we have both the keys uh with us uh which has been downloaded these are the private key which we will we will use later after that go to the network setting and here choose the VPC 2 uh subnet which is already selected because we have created only one enable public IP click on enable and the security group so here I'm just going to enable SSH Port 22 add one more Security Group select from the drop down Go to http port at and it should be from anywhere allowed to access that's done storage 8 gigs that's fine Advanced detail we just want to install the Apaches I'll just copy the script go over here past it over here and hit on launch instances so I'll be back once this EC second ec2 instance is launched all right so my both ec2 instance are up and running so I will just access the ec2 instance running under my VPC 2 I'm just going to copy this IP address to verify the Apache page so here you can see uh our Apache has been installed successfully all right so now let's take a look onto the diagram once again so our whole infra is ready but we are still uh we have not created the VPC paing so the next thing which we will do we are just going to attach and or we are just going to create a VPC paing between these two vpcs all right so let's go back to our AWS console close this everything go to the homepage and in the search box type VPC click on VPC and here in the left navigation uh you will find the option for appearing connection so click on this peering connection over here and here you can see there is no peering connection which I have created so click on create peering connection so here first of all uh we need to enter the name so I will just uh name like aing connection uh between VPC 1 and VPC 2 I'll just put a dash over here so this is the name of my peering connection select the local VPC to peer with so here I will choose VPC 1 and again the accepter VPC the other VPC which we want so that is going to be VPC 2 all right so that's uh we have selected so this is my uh first VPC and this is the second VPC and this is my VPC paing connection name and then after that you just need to click on create Beering connection and here it will ask like pending acceptance so what will happen like whenever you create a peering connection then the destination VPC should accept that peering connection so here in in the action you will find accept request button so just click on accept request and click on accept request so here you will verify the details so requestor VPC is VPC 1 from where the request is originated and acceptor is going to be the VPC 2 and these are the IP ranges uh for those VPC okay so I'll just click on accept request and now you can see our peering connection has been established so here you can see onto the diagram so now we have established our peering connection but there is one more thing which we need to set up before this whole connection works and we are able to communicate between those two ec2 instances so the next thing which we need to set is the route table so here it is showing you the message like VPC pairing connection has been established now you need to modify my route tables now so we need to modify our route table so that this whole uh connection between the vpcs works so what you need to do you just need to go to the route table first of all and here we will open the route table one by one so I'll just open the first route table over here and here into the edit route section uh here we need to add one more route so here uh see this is this route table is for VPC 1 so here you can see this is our VPC 1 so now from this route table we want to uh go to the VPC 2 so for that what we need to do we just need to put the IP range of our destination so here uh if you take a look onto the VPC so if you go to the destination so I'll open both of it over here so this is the VPC 2 and the IP range for this VPC is 13 SL 0.016 so I'll just copy this range and uh go to this route for table over here this is our route table from vpc1 in the edit routes click on ADD routes and here we need to enter the IP range of our destination so this is going to be the destination because from VPC 1 route table we are trying to connect to the VPC 2 so this is the destination and the destination for that we need a peering connection so here you will find option for a peering connection and here you can enter the peering connection ID over here and after that you can click on Save changes so this is the first side of it uh where we have set the destination to be VPC 2 IP address so click on Save changes and we have updated this route table so just close this one now and then go to another route table which is from VPC 2 and click on this route table and here click on edit routes and now we need uh add route and here we will add the destination to be the vpc1 IP ranges so here uh this is the vpc1 and here this is the IP range so it just work for opposite for here so I'll just past it over here the destination and here I will choose the peering connection here I will choose the peering connection this one and click on Save changes and here you can see our routes has been modified all right so the next thing which we will do we will just SSH into the easy to instan and and try to curl each other uh from each uh ec2 instances let's go to the AWS homepage go to our ec2 dashboard over here I'll close all the tabs and here both the instances click on both the instances and here just check the connect instructions for that so this is the one E2 instance let's start with our vpc1 E2 instance okay so click on connect and here you will find the instruction so this is the key which we have downloaded and first of all we need to change the permission of the key to be readable so just copy this command and go to your terminal over here uh just check the keys first of all and here you can see both the keys are available and both have a read and write permission that we need to change so first of all run the command CH mode 400 uh vpc1 and hit enter and similarly I will do the same thing for other key also for my ec2 instance so VPC 2 change it and I'll clear it LS l t and here you can see both the keys are now have the readon permission so first of all we will just log into our first ec2 instance so which is going to be uh yeah this one vpc1 inside my VPC 1 so this is the command to SS so I'll just copy this one go to my uh console over here I'll clear it and I'll paste the command over here and hit enter and it will ask do you want to accept the connection type yes and now we are into our ec2 instance inside my vpc1 I'll clear the screen over here I'll just open uh one more tab uh so I'll open it over here so here you can see so here on the left hand side uh this is my vpc1 ec2 instance and here this is the ec2 instance uh two from VPC to which I I will about to log in now so go to your console and uh this is the second tpe click on connect and here this is the command we already changed the permission for that ec2 key so go to terminal type the command over here type yes to [Music] connect and now we are into the ec2 instance of my VPC 2 now if our connection has been established successfully then we should be able to curl uh our Apache page from other ec2 instance so what we will do so this is my ec2 instance from vpc1 so I'm sitting over here I'll just go to my dashboard over here into ec2 and I'll just go to running instances and I'll go to ec2 instance and I'll just copy the private IP over here and I just want to access this ec2 instance into my VPC 2 from vpc1 ec2 instance so here I'll just go over here and here I will type curl and and the IP private IP address and here you can see this is the message which we were getting over there so now we are able to communicate within the vpcs so we had a two different vpcs and now we are able to uh curl or access the ec2 instance running into another VPC and similarly here you can see the address that is 13.1.1 154 and right now I am into 12 0144 which is my VPC 1 IP range and similarly if I do the curl but I need to know the IP address of my vpc1 ec2 instance so go over here go to instances click this one copy this IP address and uh yeah past it over here hit enter and here you can see the message which we are getting server details and uh these are the IP address okay let's test one more thing and I will modify the route table and after that I will not be uh access I will not be able to access those to instances so for that I'll just close everything over here and go to VPC and here into the route tables go to this first route table and I will also open the second route table and here into edit routes just remove this entry actually this one for Destination VPC so just remove this one and after that you will not be able to access uh the ec2 instances from each other and similarly into another route table I'll just remove this entry for Destination uh VPC I'll just remove this one and click save changes now uh both the route table has been updated and let's go back and uh let's do the curl one again and here you can see the request is not going through and similarly over here the request is not going through so this is the uh VPC paing and how you can establish the VPC pairing between the different vpcs Pres sent inside your AWS account I hope you likeed the today's session on a VPC peering and if you're interested into the similar content uh then keep following this Channel and also I have a premium content which is available onto my YouTube membership program so please uh go there and join if you feel like joining those sessions so see you into the next session of our devops till then take care and bye-bye
Info
Channel: Rahul Wagh
Views: 18,259
Rating: undefined out of 5
Keywords: aws, vpc peering, vpc, devops, cloud
Id: 36qsohuPzMQ
Channel Id: undefined
Length: 24min 50sec (1490 seconds)
Published: Mon Oct 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.