END-TO-END SOLUTION DEPLOYED ON AWS USING VPC, S3 & EC2.

Israelowolabi
9 min readJun 30, 2023

--

In this project, I configure a repeatable environment for a publicly available website by using the Virtual Private Cloud (VPC), Amazon Simple Storage Service (Amazon S3) and Elastic Compute Cloud (EC2) services.

TASKS

1. Create a Virtual Private Cloud (VPC) environment for the EC2 instances.

2. Create an Amazon S3 bucket that will hold the static web content for the website.

3. Create a custom EC2 launch template that includes the web server engine and an initial homepage for the website. Deploy a web server based on the launch template and verify that the website is publicly available from the new EC2 instance.

TASK 1. Create a VPC

Step 1: From your AWS Console, type vpc in the search bar, and under services select VPC

Step 2: Select Create VPC

Step 3: Choose a valid IPv4 CIDR and select Create VPC

Step 4: Select Subnets and Create subnet

Step 5: Select the VPC created earlier and input a valid IPv4 CIDR block for your subnets (2 public & 2 private) then at the very bottom select Create subnet

Step 6: Select internet gateways and Create Internet gateway

Step 7: Attach Internet gateway to the VPC created earlier

Step 8: Create route table (public route table)

Step 9: Edit routes & add internet gateway in public route table

Step 10: Select Edit subnet associations, select public subnets and Save associations

Step 11: Create route table (private route table)

Step 12: Select Create NAT gateway, select a public subnet, Allocate Elastic IP, then select Create NAT gateway

Step 13: Edit routes & add nat gateway in private route table

VPC is ready to go!

TASK 2. Create an S3 bucket

Step 1: From your AWS Console, type s3 in the search bar, under services select S3 and Create bucket

Step 2: Choose a unique bucket name, under the Object Ownership section, make sure that Access Control Lists (ACLs) are left disabled as recommended, this helps to ensure the security of your bucket contents. Uncheck the option that says “Block all public access”, this ensures that objects in your bucket are accessible by the public and finally create bucket.

Step 3: Upload object (usually zipped). I used a template found here.

Step 4: Click on the Destination link, go to Permissions, under Bucket policy select edit and click on policy generator.

Step 5: Under Select type of policy click S3 bucket policy, under Principal insert * which signifies all, under Actions select GetObject, copy your Bucket ARN and insert under Amazon Resource Name (ARN), then select Add Statement, Generate Policy & copy the policy generated.

Step 5: Paste the policy generated and add /* after bucket name (so it applies to all objects in the bucket) and save changes.

TASK 3. Create Launch Template

Step 1: From your AWS Console, type ec2 in the search bar, under services select EC2, and Create security group.

Step 2: Under VPC select the VPC created earlier, under Inbound rules allow access to Port 80 for web access from anywhere and Port 22 for ssh access from my IP, and Create security group.

Step 3: Create key pair. Here RSA and PEM is utilized.

Step 4: Create launch template, under Application and OS images select ubuntu, ubuntu 20 is utilized here, Instance type is t2 micro, under key pair select key pair created earlier, under network settings select one of the public subnet created earlier, select the security group created earlier and enable auto assign public IP under advanced network configuration.

Step 5: Under Advanced details, scroll to the bottom and input web server provisioning script. This script should be capable of downloading the web files from the S3 bucket and hosting your website on an EC2 instance, then select Create launch template

#!/bin/bash

sudo -i

sudo apt update

sudo apt install apache2 wget unzip -y

wget https://test-bucket-2023-06-28.s3.amazonaws.com/2128_tween_agency.zip

unzip 2128_tween_agency.zip

sudo cp -r 2128_tween_agency/* /var/www/html/

sudo systemctl restart apache2

Step 6: Click on the template created, under Actions select Launch instance from template, you can choose to modify configurations or not, then select Launch instance.

Step 7: Click on the instance created, wait till Status check changes from initializing to 2/2 checks passed. You can also choose to name the instance by clicking on the edit symbol under name. Copy public IP address when passed and paste in browser, website should be up and running. You can also access the instance via ssh.

Clean up

EC2

1. Terminate instance

2. Delete Security Group

3. Delete key pair

4. Delete launch template

S3

1. Delete object

2. Delete bucket

VPC

1. Delete nat gateway

2. Delete subnets

3. Detach Internet Gateway, delete Internet Gateway

4. Delete VPC, which will delete the route table and any other resource

5. Release elastic IP

#devops #aws #cloud #s3 #vpc #ec2

--

--