Creating Static Web pages on AWS
Tags: aws, s3, lambda, cicd
Published: 2024-03-11 11:51:48

AWS is a great choice to host static websites because it provides all the tools you need to scale, host and deploy simple sites. If you needed to create a quick promotional site or Resume, it would be a perfect choice. 

In this short post I will look at what I learned as I put together a simple website project.

**Building Static Websites Using Amazon S3**

Building static web pages on AWS with Amazon S3 offers several advantages:

**Cost-Effective:** You only pay for the storage used and data transferred, which is generally much lower than traditional hosting services. 
**Scalability and Performance:** Amazon S3 is designed for high scalability and performance. It can handle large amounts of traffic without any issues, and its global network of servers ensures low latency and fast loading times for users across the world. 
**Reliability and Durability:** S3 provides a highly reliable and durable infrastructure for hosting static websites. 
**Easy Deployment and Management:** Deploying a static website on Amazon S3 is straightforward and can be done quickly using the AWS Management Console, AWS CLI, or you can use a CI/CD setup using github.

**The importance of infrastructure as a code**

If you work as a team, Infrastructure as code is a must as it will allow you to collaborate and see what changes are being made. In addition if there is a disaster, you will be able to quickly redeploy your infrastructure. You can deploy code using the AWS specific tool which is SAM or if you prefer, Terraform, which is cloud agnostic and can work with AWS, GCP and Azure.

**DNS and Route 53**

Linking the S3 site to a domain Using Route 53. DNS servers respond to queries on port 53 and provide answers that route end users to your applications on the Internet.

This will mean that you can specify your own domain name for a public S3 Bucket that is distributed through a cloudfront distribution.

**CloudFront and HTTPS**

Cloudfront is a content distribution network that allows you to distribute your content all over the world. This is important because it makes the performance of the page good no matter where you are. This cloudfront configuration can be set up using the infrastructure as a code template and deployed using SAM.

Other advantages are that you can have an HTTPS connection - this means that connections are encrypted with https when CloudFront communicates with viewers, and you can also password protect your site if you wanted to.


**Using Lambda to connect to a Dynamo DB**

If you require a site to communicate to a database, for example to display a counter of the number of viewers of a page, you can implement a lambda function with a function URL to communicate with the correctly setup DynamoDB. With the correct permissions the function URL can then communicate and update the DB using javascript from the web page.

**IAM**

AWS provides a great system for managing users and components of the AWS system. 

When setting up Identity and access management using AWS always make sure that the root account is secured using MFA and create a user with a role applied to it for day to day operations. If the project is a bigger one with many users, use AWS organisations.

The individual components of AWS also need to be able to communicate with each other - you will need to create a policy in order for a Lambda function to communicate with Dynamo DB for example.

**Diagram of a Simple Site**


![Diagram of a simple website using AWS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38bta1hil5rdm8k05z62.png)