Using AWS to Host a Static Website - Part 1
- Jamie Tyler
- Aws
- December 13, 2024
Table of Contents
For years I have been uses various platforms to host a static website and one of the easiest ways, for me, has been to use AWS services to do so. At the core of it, there is Amazon S3 which is cheap and easy to configure as a static website. You can add several other AWS services to this to provide a scalable and robust solution for hosting a static website.
Core Components
To host a website there are several components.
- A mechanism to create the web pages i.e. the content
- Some where to store and serve the content
- DNS resolution
- SSL certificates to make it secure
Optionally a Content Delivery Network (“CDN”) can be used to accelerate the rendering of the website pages in locations far away from where the website is hosted.
As I have decided to use AWS to host the website, what services can help me.
- A mechanism to create the web pages i.e. the content - a static website generator e.g. Hugo
- Some where to store and serve the content - Amazon Simple Storage Service (Amazon S3)
- DNS resolution - Amazon Route 53
- SSL certificates to make it secure - AWS Certificate Manager
- CDN - Amazon CloudFront
So, how do I bring these all together to achieve this? Over the coming posts I will walk through each component, its configuration etc. for a static website. Before that, I will be using Infrastructure-as-Code (“IaC”) to do this and as this is only for AWS I will be using AWS CloudFormation.
Infrastructure-as-Code (“IaC”)
AWS’ definition is as follows.
Infrastructure as code (IaC) is the ability to provision and support your computing infrastructure using code instead of manual processes and settings. Any application environment requires many infrastructure components like operating systems, database connections, and storage. Developers have to regularly set up, update, and maintain the infrastructure to develop, test, and deploy applications.
Manual infrastructure management is time-consuming and prone to error—especially when you manage applications at scale. Infrastructure as code lets you define your infrastructure’s desired state without including all the steps to get to that state. It automates infrastructure management so developers can focus on building and improving applications instead of managing environments. Organizations use infrastructure as code to control costs, reduce risks, and respond with speed to new business opportunities.
Reference: What is Infrastructure as Code?
The point of using IaC is so that I can create a repeatable method of quickly and safely deploying a static website on AWS. All I need to do is pass in the parameters required to provide the unique dimensions associated with the specific static website I want to create.
Using IaC requires planning and a good understanding on how resources are created for a specific AWS service and how AWS services can be linked together to deploy the whole “solution” not just the components including the sequence they need to be created in. Over the coming series of posts I will build up the CloudFormation template so it includes all the AWS services that will be consumed. As I am not going to have 100s of lines in the template, I won’t be using nested-stacks or modules.
To understand CloudFormation it is useful to read How CloudFormation Works.