In this article, we will discuss some of the basic things you need to know about hosting a static website on AWS, as well as the concrete steps on how you can do it yourself.
What is a static website?
Static websites are essentially web pages with static or fixed content. It is delivered to the user’s browser exactly the way it was stored. Moreover, its contents or appearance doesn’t vary depending on the users. It is ideal for
You may be wondering, how does a static website differ from a dynamic website. Static websites also load a lot quicker than dynamic sites. Moreover, in terms of security, code injection threats are quite minimal. Hacks are also less likely to occur as opposed to dynamic sites. Static websites are also highly scalable.
What is AWS?
Amazon Web Services or AWS is a cloud service platform where you can host your website. With AWS, you can create a website for free. Moreover, they offer tons of features that make it easier to set up any kind of website you desire. Some of their free product offers include Amazon EC2, Amazon Lightsail, AWS Lamda, Elastic Load Balancing, AWS Amplify Console, and Amazon S3.
Hosting a static website on AWS
Now that we have discussed the basics, let’s move on to the exact steps on how you can do web hosting on AWS.
Use Amazon S3 Web Hosting or AWS S3
AWS Simple Storage Service or S3 is one of Amazon’s oldest services. It allows users to host static websites without a server. Thus, it is easy to set up and you can get your static website running in a short time.
Create an Amazon S3 bucket.
You can do this by opening Amazon’s management console. Here, you can create an Amazon S3 bucket. You will be asked to choose an AWS region where your files will be stored. Make sure to choose the geographic location that’s most suitable for your site. Some factors to consider are your static website visitors’ location, data center locations, as well as regulatory requirements. Note that some countries restrict data. You might want to research more about this if you are unsure.
Create an Amazon bucket name.
The next thing to do is to choose a bucket name. Make sure that it complies with DNS naming conventions. If you have an existing domain and want to use it, you should use it as your bucket name. For example, your domain is ʼwww.staticwebsite.com’, then the bucket name should also be at ‘www.staticwebsite.com’.
Some rules for naming S3 buckets are as follows:
- Names should begin with either a letter or a number.
- It should be around 3 to 63 characters long.
- It should be composed of lowercase letters, numbers, hyphens, and dots.
- Names can’t follow a format of an IP address. An example of an IP address is 220.127.116.11
Here are some examples of valid bucket names to give you an idea.
Enable Amazon S3 web hosting feature.
Using the management console, you can enable the web hosting feature. Go to bucket properties. Then, select ‘Static Web Hosting’. Then choose to use the bucket to host your website.
Perform configuration of the bucket.
Without writing any kind of code, you can configure your S3 bucket as a static website. Just go to Bucket Properties and perform the necessary configurations. Here, you can provide the Index Document, as well as the Error Document.
Upload your web content files.
Now everything’s all set, you can now begin uploading your web files. You can do so using the AWS Management Console. You may also use other tools such as CloudBerry, S3 Bucket Explorer, or S3 Fox to do this.
Enable public access.
Amazon S3 makes use of a security-by-default policy. Thus, you need to manually configure it so that visitors can view your content. Otherwise, newly uploaded content will show an ‘Access Denied’ error to your visitors.
To circumvent this, you need to use an Amazon S3 bucket-wide policy. This determines who gets to see your static website’s content.
Request a certificate.
Choose the domain name you wish to request a certificate for. Then, choose your desired validation method. It can be through DNS or an email address. Review the validation methods. Make sure all data are correct. Once reviewed, you can now validate.
If you chose the DNS validation route, create a CNAME for each domain in the DNS configuration. If you’re using Amazon Route 53 to manage, select ‘Create Record in Route 53’ so ACM will handle the DNS configuration. Otherwise, you can download the DNS configuration file and put it in your web service’s DNS.
Once finished, the status should change from ‘Pending Validation’ to ‘Issued’.
Here are some optional steps you can do to optimize your static website with AWS.
Use Amazon CloudFront to speed up your website.
If you wish users to fetch data from origin servers as fast as possible, Amazon
CloudFront can do it for you.
Use HTTPS to encrypt data when visitors load your content.
Simply change viewer protocol to ‘HTTPS Only’ or ‘Redirect to HTTP or HTTPS’ to activate this.
Check Amazon CloudFront reports.
If you have chosen to use Amazon CloudFront, you can check your site’s analytics.