Deploy Scalable VPC Architecture on AWS Cloud

Deploy a Modular and Scalable Virtual Network Architecture with Amazon VPC. Pre-Requisites 1] AWS Account: Ensure you have an AWS account with necessary permissions (IAM Role or User with privileges). 2] Source Code: Prepare the web application repository hosted on GitHub/ BitBucket. Pre-Deployment 3] Golden AMI: Launch an EC2 instance with a public subnet. (Ubuntu 24.0) 4] Install dependencies: Update sudo and install Apache Web server, Git, CloudWatch Agent, and AWS SSM Agent. Install Apache Web Server: sudo yum install httpd sudo enable systemctl httpd sudo start systemctl httpd Install Git sudo yum install git -y git --version Install CloudWatch Agent □ Download the CloudWatch Agent- sudo yum install amazon-cloudwatch-agent □ Configure and start the agent: - sudo systemctl enable amazon-cloudwatch-agent □ Save the File: Ensure the file is saved at this path: /opt/aws/amazon-cloudwatch-agent/bin/memory_metrics.json. □ Example command to copy the file: sudo cp /home/ubuntu/VPC-Architecture/VPC Architecture/memory_metrics.json /opt/aws/amazon-cloudwatch-agent/bin/memory_metrics.json □ Apply the Configuration File: If you prefer to keep the file in the original location, run: ```sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/home/ubuntu/VPC-Architecture/VPC\Architecture/memory_metrics.json -s ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6wg6ilrezvshv1gphsi1.png) - Install AWS SSM Agent □ Install the AWS SSM Agent - sudo yum install amazon-ssm-agent -y ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5bufns3xj9szetyujv57.png) □ Start and check status of cloud watch service: - `sudo systemctl start amazon-cloudwatch-agent` `sudo systemctl status amazon-cloudwatch-agent` ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6a8m2555br0rmucx6a2g.png) - Navigate to the **CloudWatch Dashboard** in AWS and go to **Metrics**. You should see the custom metrics created. ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5fqxakgxrsmm919nxex7.png) - Check the CloudWatch logs captured in amazon-cloudwatch-agent.log ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/byqd2vm2zwy3yic831mu.png) 5] **Create AMI - Amazon Master Image** - Navigate to the AWS EC2 Dashboard. - Select the Stopped EC2 Instance. - From the Actions Menu, choose: □ Image and templates > Create Image. - Provide the following details: □ Image Name: Give your AMI a descriptive name, e.g., GoldenAMI-v1. □ Description: Mention what this AMI includes. □ No Reboot: Leave unchecked (default) to ensure a clean AMI. - Click Create Image and wait for the process to complete. ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s50rlvys5dt6ju228qsg.png) 6] **Test the Golden AMI** by launching new EC2 instance with created AMI - Launch an EC2 Instance from the Golden AMI - Log in to your AWS Management Console. - Go to the EC2 Dashboard. - Click on Launch Instance and choose My AMIs. - Select your Golden AMI and configure the instance settings: □ Select an instance type (e.g., t2.micro for testing). □ Attach the appropriate security group. □ Assign a public IP for SSH testing. □ Add necessary storage if required. □ Assign an IAM role that matches your AMI's requirements (e.g., SSM access). □ update the user data with script in the image ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qjq8wvkw07p6756dgm3q.png) ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ry39l19mtxu3h2kqosa.png) 7] **Verify Connectivity** - Connect to the instance using SSH :ssh -i "key_name.pem" ubuntu@ec2-18-222-53-96.us-east-2.compute.amazonaws.com - Create a new IAM role and assign to EC2 **Step 1: Access the IAM Console** 1. Go to the IAM Console. 2. Click on the "Create role" button. **Step 2: Specify Trusted Entity** 1. Select trusted entity type: Choose AWS service. 2. Use case for other AWS service: Select EC2. 3. Click Next. **Step 3: Attach Policies** 1. Search for and select the following policies: _AmazonSSMManagedInstanceCore_ (required for SSM functionality) _CloudWatchAgentServerPolicy_ (if you're using CloudWatch Agent for monitoring). 2. Click Next. **Step 4: Add Tags (Optional)** 1. Add any tags if required for identification or cost tracking. 2. Click Next. **Step 5: Review and Create** 1. Provide a Role name: Example- **EC2_SSM_Access_Role**. 2. Review the permissions and confirm that AmazonSSMManagedInstanceCore is included. 3. Click Create role. **Step 6: Attach Role to the EC2 Instance** 1. Go to the **EC2 Console**. 2. Select the instance you want to associate the role with. 3. Click Actions > Security > **Modify IAM Role**. 4. Select the newly cr

Mar 30, 2025 - 07:41
 0
Deploy Scalable VPC Architecture on AWS Cloud

Deploy a Modular and Scalable Virtual Network Architecture with Amazon VPC.

Pre-Requisites

1] AWS Account: Ensure you have an AWS account with necessary permissions (IAM Role or User with privileges).
2] Source Code: Prepare the web application repository hosted on GitHub/ BitBucket.

Pre-Deployment

3] Golden AMI:

  • Launch an EC2 instance with a public subnet. (Ubuntu 24.0)

Image description

Image description

4] Install dependencies:

  • Update sudo and install Apache Web server, Git, CloudWatch Agent, and AWS SSM Agent.

  • Install Apache Web Server:
    sudo yum install httpd
    sudo enable systemctl httpd
    sudo start systemctl httpd

Image description

Image description

  • Install Git
    sudo yum install git -y
    git --version

  • Install CloudWatch Agent

□ Download the CloudWatch Agent- sudo yum install amazon-cloudwatch-agent

Image description

□ Configure and start the agent: - sudo systemctl enable amazon-cloudwatch-agent

Image description

□ Save the File: Ensure the file is saved at this path: /opt/aws/amazon-cloudwatch-agent/bin/memory_metrics.json.

Image description

□ Example command to copy the file: sudo cp /home/ubuntu/VPC-Architecture/VPC Architecture/memory_metrics.json
/opt/aws/amazon-cloudwatch-agent/bin/memory_metrics.json

□ Apply the Configuration File: If you prefer to keep the file in the original location, run:

```sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/home/ubuntu/VPC-Architecture/VPC\Architecture/memory_metrics.json -s




![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6wg6ilrezvshv1gphsi1.png)




- Install AWS SSM Agent

□ Install the AWS SSM Agent - sudo yum install amazon-ssm-agent -y

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5bufns3xj9szetyujv57.png)


□ Start and check status of cloud watch service: - 
  `sudo systemctl start amazon-cloudwatch-agent`
  `sudo systemctl status amazon-cloudwatch-agent`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6a8m2555br0rmucx6a2g.png)



- Navigate to the **CloudWatch Dashboard** in AWS and go to **Metrics**. You should see the custom metrics created.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5fqxakgxrsmm919nxex7.png)

- Check the CloudWatch logs captured in amazon-cloudwatch-agent.log

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/byqd2vm2zwy3yic831mu.png)


5] **Create AMI - Amazon Master Image**

- Navigate to the AWS EC2 Dashboard.

- Select the Stopped EC2 Instance.

- From the Actions Menu, choose:
□ Image and templates > Create Image.

- Provide the following details:
□ Image Name: Give your AMI a descriptive name, e.g., GoldenAMI-v1.
□ Description: Mention what this AMI includes.
□ No Reboot: Leave unchecked (default) to ensure a clean AMI.

- Click Create Image and wait for the process to complete.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s50rlvys5dt6ju228qsg.png)


6] **Test the Golden AMI** by launching new EC2 instance with created AMI 

- Launch an EC2 Instance from the Golden AMI

- Log in to your AWS Management Console.

- Go to the EC2 Dashboard.

- Click on Launch Instance and choose My AMIs.

- Select your Golden AMI and configure the instance settings:

   □  Select an instance type (e.g., t2.micro for testing).
   □  Attach the appropriate security group.
   □  Assign a public IP for SSH testing.
   □  Add necessary storage if required.
   □  Assign an IAM role that matches your AMI's requirements (e.g., SSM access).
   □ update the user data with script in the image


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qjq8wvkw07p6756dgm3q.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ry39l19mtxu3h2kqosa.png)



7] **Verify Connectivity**

- Connect to the instance using SSH :ssh -i "key_name.pem" ubuntu@ec2-18-222-53-96.us-east-2.compute.amazonaws.com

- Create a new IAM role and assign to EC2

**Step 1: Access the IAM Console**

1. Go to the IAM Console.
2. Click on the "Create role" button.

**Step 2: Specify Trusted Entity**

1. Select trusted entity type: Choose AWS service.
2. Use case for other AWS service: Select EC2.
3. Click Next.

**Step 3: Attach Policies**

1. Search for and select the following policies: _AmazonSSMManagedInstanceCore_ (required for SSM functionality)   _CloudWatchAgentServerPolicy_ (if you're using CloudWatch Agent for monitoring).
2. Click Next.


**Step 4: Add Tags (Optional)**

1. Add any tags if required for identification or cost tracking.
2. Click Next.

**Step 5: Review and Create**

1. Provide a Role name: Example- **EC2_SSM_Access_Role**.
2. Review the permissions and confirm that AmazonSSMManagedInstanceCore is included.
3. Click Create role.


**Step 6: Attach Role to the EC2 Instance**

1. Go to the **EC2 Console**.
2. Select the instance you want to associate the role with.
3. Click Actions > Security > **Modify IAM Role**.
4. Select the newly created IAM role (**EC2_SSM_Access_Role**).
5. Click Update IAM role.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lv1h5dsu3is2uslkvzc4.png)


- Setup Permission for S3 bucket

□ Navigate to IAM, in the dashboard select Roles.
□ Click Create Role.
□ Select permission policies, AmazonS3ReadOnlyAccess and other required policies


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3sd9a4ihprf76m6u8lt7.png)

## VPC Deployment

- Create VPC network ( 192.168.0.0/16 ) for Bastion Host deployment

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aswfihgxgnrclmkydpzt.png)

- Create a VPC network ( 172.32.0.0/16 ) to deploy scalable application servers


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xft9mfrsqfa2c9okxxht.png)

- Access the VPC dashboard to display the created VPC

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6ayc3p7qp7b2x9a7d7v.png)

- Create Internet gateways to attach the gateways to Bastion app (ed-vpc-01)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/47pwul4rtwobmlt4l4q7.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/14p3bd8ixgv4w3v8nzwu.png)


- Create a public subnet for bastion app (ed-vpc-01) and configure the subnet 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p47vq1bxzao6rhdnv60x.png)

- Create a two public subnet and two private subnet for application server VPC (ed-vpc-02) with IP- 172.32.0.0/16 .

1. **Public Subnet 1 (ed-pub-sub-01)**: `172.32.1.0/24`
2. **Public Subnet 2 (ed-pub-sub-02)**: `172.32.2.0/24`
3. **Private Subnet 1 (ed-priv-sub-01)**: `172.32.3.0/24`
4. **Private Subnet 2 (ed-priv-sub-02)**: `172.32.4.0/24`



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rfd5jz0z9q08xw8qde4i.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ise2j5ohixbpjmskgca0.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gdvyfh5zaliezca9i0y6.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydnn2b8zr9rd60wi5spw.png)


- Create NAT Gateway(ed-nat-gw-01) in Public Subnet (ed-pub-sub-02) and update Private Subnet  associated Route Table accordingly to route the default traffic to NAT for outbound internet connection.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wg1w9r498ovtlm76mac9.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hua1vrbsy54qdawgpimi.png)


1. Create public route table (ed-rt-vpc-01-pub) for VPC (ed-vpc-01)![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s0qc6bh0r58cqhms6mc2.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/prnen8xi9931uck092al.png)
2. Create public route table (ed-rt-vpc-02-pub) for VPC (ed-vpc-02) ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3vtcqtcgdwik00fuj0wd.png)
3. Create private route table (ed-vpc-02-priv-01) for VPC (ed-vpc-02)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i4byscy6ni68axacqx7h.png)
4. Subnet associated with route table (ed-rt-vpc-02-pub)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i7mrxm1tk6jgha963dav.png)
5. Subnet associated with route table (ed-rt-vpc-01-pub) 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qlo59hjyb1lazrrt8vy1.png)
6. Subnet associated with route table (ed-rt-vpc-02-pub) 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vr9g1yi7r2due3zj98dt.png)




- Create Internet Gateway for each VPC and Public Subnet associated Route Table accordingly to route the default traffic to IGW for inbound/outbound internet connection.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ml599xuyyup7t620asy.png)

- Create Transit Gateway and associate both VPCs to the Transit Gateway for private communication.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4c7hsf6dcfjw1jr1hdn4.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40tkk65ziqbhpiteqcpd.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1p5z8f7w7dajgnz9b0zd.png)

- Create Cloudwatch Log Group with two Log Streams to store the VPC Flow Logs of both VPCs and enable Flow Logs for both VPCs and push the Flow Logs to Cloudwatch Log Groups and store the logs in the respective Log Stream for each VPC.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/garo6q42qr8o2iqcv2n7.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/brrypmef92zfoljaamet.png)

- Create Security Group for bastion host allowing port 22 from public.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8u3j7q39w3kdkxqm2qz.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0686qet7vxqltkh7nwvz.png)

- Create Target Group (tg-01) and associate it with ASG.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7srcmxbmvm2rq6cb301i.png)

- Create Network Load balancer in Public Subnet and add Target Group as target.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqzb76idonapv0w6jjo3.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e6t2d4yw4xdb7uq99uuf.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tjycivnmne3c5w93t2yr.png)

- Create Auto Scaling Group with Min: 2 Max: 4 with two Private Subnets associated to 1a and 1b zones.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/109fpgk95kmno4ptqy9e.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5on5bnrqy4uyp2gv61cb.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xyvyftqvnfboj4a7paw.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/no5yl85lye5c1dmzps3l.png)


- Update route53 hosted zone with CNAME record routing the traffic to NLB. For that initially create record in Route53 > Hosted Zone 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11i51rl725sfp8untvhr.png)


## Validation

- As DevOps Engineer login to Private Instances via Bastion Host.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rmibl8g0056rqa6zd3mq.png)

- Login to AWS Session Manager and access the EC2 shell from console.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1hfal3qiw93wk3sqfgzp.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qnht0l1g4q1f3h1t1k2v.png)