Feb 25, 2023 7 min read

Deploying a Static Website in AWS (Apache EC2) [Free] // Part 1 // The Manual Way

Deploying a Static Website in AWS (Apache EC2) [Free] // Part 1 // The Manual Way
Table of Contents

This tutorial shows you how to use Webflow to design a static webpage, export the code, then deploy it on a free Apache Web server with AWS EC2.

TL;DR // The Problem & Solution

I want to manually deploy a static website for free on the internet using AWS and some of their tech:

  • S3 - storing the website code as it’s changed (was required for my class)
  • EC2 - run it as an Apache Web Server to serve the static webpage

I'll use Webflow to design a static webpage and export the HTML, CSS, and javascript. I'll put this into an S3 bucket, then tell an EC2 Apache server instance to use the code. Static websites don't require any server-side functionality. Everything happens in the client code that I export. In other words, when a user goes to the website, everything about the website runs in their browser and there's no need for extra calls to another server. This is useful when needing to post quick little info websites or something of that nature.

Build a Free Website Tech Stack with AWS as the Cloud Provider

This is the architecture I will be delving into…pretty sure this is generally how it works.

0001-Untitled-1

3 Options for AWS Apache EC2 Web Server: AWS Setup vs. IaC (Infrastructure as Code) vs. Deploying Containers to AWS

  • AWS Setup - Upload code, setup infrastructure, and deploy using the dashboard on the AWS website.
  • IaC (Infrastructure as code) - write configuration files (usually JSON format) that are fed into software like Terraform to procure cloud infrastructure and setup the website and everything automatically. The power in this is that you avoid GUIs and CLIs, and you can store these config files to be replicated and used in other situtations. This can make consistent security a bit easier in an organization.
  • Deploy containers - use Docker or Kubernetes to deploy containers to AWS that have predefined configurations

I will be focusing on the AWS Setup.

Building a Quick Website

I’m using Webflow to create a small static website.

I found a template on Popular Websites - Webflow

0002-Untitled-2

Clone it.

0003-Untitled-2

Change some stuff.

0004-Untitled-1

Export it.

0005-Untitled-1

0006-Untitled-1

The Traditional Way // Using AWS Dashboards and UI

Set up S3 Bucket

Create an S3 bucket.

0007-Untitled-1

Success.

0008-Untitled

Upload the website folder exported and unzipped from webflow.

  • It might work zipped too. I haven’t tried that.

0009-Untitled

Upload success.

0010-Untitled

Give use case access for EC2 instances, so that the website code stored in EC2 can be used by the EC2 server.

0011-Untitled

Use the “AmazonS3FullAccess” permission.

  • Definitely not the most secure, but alright for testing.

0012-Untitled

Set up EC2 Instace (will run the Apache Web Server)

This is what will be used to serve our website.

Name it and give it a description.

0013-Untitled

Go to the left and find “security groups” and create one for the instance.

0014-Untitled

Name it and give it a description.

0015-Untitled

Give it some inbound and outbound rules.

0016-Untitled

Setup a key pair to be used to connect to the instance for setup.

  • If downloaded, you can use it with PuTTY, but this is not as simple IMO.

0017-Untitled

Create the EC2 Instance

Name the EC2 instance.

0018-Untitled

Select the created key-pair.

0019-Untitled

Select the permissions for the S3 in “Advanced Details.” This will allow the EC2 to grab the website code from the S3 bucket.

0020-Untitled

EC2 creation success.

0021-Untitled

Summary of the instance (blurred out details).

  • Click “Connect” in the top right.

0022-Untitled

Connect to the instance or use another SSH client like PuTTY.

0023-Untitled

Setup the EC2 Server in the Connected Terminal

Escalate privileges and update the yum packages.

sudo su

yum update -y

0024-Untitled

Install Apache service.

yum install httpd -y

0025-Untitled

Configure httpd (Apache service) to be on.

chkconfig httpd on

0026-Untitled

Try to put website code into the html folder (accessed by Apache).

cd /var/www/html

aws s3 sync s3://bensbucket-cloudsecclass /var/www/html

0027-Untitled

Make sure I have the security group added.

0028-Untitled

Make sure I have the IAM rule set so the EC2 server can access the S3 bucket.

0029-Untitled

More errors…why?

0030-Untitled

Inbound rules??? None???

0031-Untitled

Set up inbound rules for security group.

0032-Untitled

Worked!!

0033-Untitled

Run the commands again:

sudo su
chkconfig httpd on
cd /var/www/html
aws s3 sync s3://bensbucket-cloudsecclass /var/www/html

Worked again!!

0034-Untitled

Start the Apache Server!

service httpd start

  • This will tell code to start running to greb the website files and serve them to incoming requests for the “index” or home page.

0035-Untitled

Worked, but where’s my website????

0036-Untitled

Looks like it may be because Apache can’t directly see my “index.html” file in the “html” folder.

0037-Untitled

Stop the Apache service for a little:

service httpd stop

0038-Untitled

Try to move the child subdirectories of the webflow export folder out of the folder, so that they are in the html folder:

cd ..

mv cybers-stunning-site.webflow/* ./

sudo rm -d cybers-stunning-site.webflow/

0039-Untitled

Start the Apache web server again:

service httpd start

Worked!!!

0040-Untitled

Fixing Mistakes

Uploading the Files correctly to the S3 bucket

We can’t simply upload the folder. We have to upload what is inside of the folder.

Delete the old upload.

0041-Untitled

Select the files inside the folder and upload.

0042-Untitled

0043-Untitled

Update the code in the /var/www/html folder again.

If you need to navigate to the folder, cd /var/www/html

0044-Untitled

Worked.

0045-Untitled

Part 2

In part 2, I'll talk about how to use Terraform to automate the process of procuring infrastructure and deploying a website quickly and securely with infrastructure as code. This will make the whole process more efficient, repeatable, and will allow for more flexibility. Not to mention, clicking through GUIs is lame sometimes.

Questions & Exploration

  • Automatic Website Deployment and CI/CD
    • How do we have the code automatically updated when new website code is pushed to the S3 bucket via GitHub or even manual uploads?
    • Is this how websites are usually deployed?
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Cybersader.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.