To allow an EC2 instance in the production environment to download packages, libraries, software, and Docker images stored in ECR, the VPC of the production environment must have a NAT Gateway. This allows EC2 instances in that network to access the internet and download the necessary resources via the NAT Gateway.
In the VPC interface:
We will configure the VPC with the following details:
nat-gw
Now we will add a new route in the routing table that is connected to the private subnet where the EC2 instance is located. This route will go to the NAT Gateway.
0.0.0.0/0
Now, this private subnet can access the internet through the NAT Gateway and Internet Gateway. We can verify this in the Resource map tab under Your VPCs.
In theory, with the configuration we’ve done so far, the EC2 instance in the development environment should be able to SSH into the EC2 instance in the production environment. Let’s test this.
First:
Open MobaXterm or VSCode. In this guide, we are using MobaXterm.
ec2-user
Next, we will upload the .pem
file to the EC2 instance using MobaXterm to establish an SSH connection to the EC2 instance in the production environment (both EC2 instances are using the same key-pair).
In the Instances interface:
imga-server
Enter the following command in the command line:
chmod 400 <your-key>.pem
ssh -i <your-key>.pem ec2-user@<private ipv4>
And we get the following result:
With this, the configuration steps we have completed are correct. In the next section, we will explore how our system is deployed.