Exploring Amazon S3
Hello!
I’ve been preparing for the Amazon Web Services (AWS) Solutions Architect certification and recently learned about the S3 storage service, which I will be exploring in today’s blog in detail.
What is Amazon S3?
Amazon S3, short for Amazon Simple Storage Service is an object-based cloud storage service provided by Amazon under the Amazon Web Services (AWS) family of cloud products.
The S3 service aims to provide the following gurantees:
- Secure
- Highly available
- Scalable
- High performance
- Durability (99.999999999% - Amazon’s 11 9’s promise!)
Some specifics
- Files can range from 0 bytes to 5 terabytes in size.
- Virtually unlimited storage
- Collections of files are stored in objects called Buckets
- All buckets on the S3 platform exist in a single global namespace and hence each bucket should have a unique name, globally.
-
A unique URL is generated against each bucket.
[Image source: Amazon.com]
Data consistency model
The Amazon S3 platform provides the following two data consistency gurantees:
-
Read after Write consistency for newly-uploaded files.
For example, if I upload a new file titled test.txt to an empty bucket, and immediately try to access test.txt, I will be able to access the file with no issues.
-
Eventual consistency for updates and deletes.
For example, I now make an edit to the previously-uploaded test.txt and re-upload it to my bucket. Now, when I try to immediately access test.txt, it is not guranteed what version I will be served, it may either be the old version or the new. However, eventually, I will always be served the latest version of test.txt.
Similarly, when I delete test.txt from the bucket, it may still be stored on the S3 servers for some time, however, eventually, the file will be deleted.
Features
-
Versioning - allows multiple versions of the same object to be stored in the S3 bucket.
-
Static website hosting - the S3 service allows hosting static HTML web pages with no support for server-side scripting for dynamic content such as PHP.
-
Access Control Lists (ACLs) - provide control of access to specific files within a bucket.
-
Bucket Policy - similar to ACLs, however these implement bucket-wide policies as compared to object-specific policies in case of ACLs.
-
Server-side encryption - controls whether data within S3 servers is encrypted before storage.
Demo and Tutorial
Creating an Amazon S3 bucket
-
From the AWS Services page navigate to S3 under the Storage category.
-
Click Create bucket.
-
In the Create bucket page, do the following:
i. Choose a unique Bucket name.
ii. Select the Region where you would like the bucket to be stored.
iii. Configure access to bucket via ACLs or Bucket Policy.
-
Finally click Create bucket.
-
The bucket is created:
Enabling bucket access logging
-
Repeat the bucket creation procedure described in the previous section to create a bucket for log storage.
-
From the bucket homepage, navigate to Properties
-
Click on the Server access logging tile.
-
Click Enable logging.
-
In the Target bucket section choose the bucket you created in Step 1.
-
In the Target prefix section choose a prefix that you want to prepend to all log files for easy filtering.
-
Finally press save!
Enabling object versioning
-
From the bucket homepage, navigate to Properties.
-
Click on the Versioning tile.
-
Click Enable versioning.
-
Click Save.
-
To see versioning in effect lets upload an empty text file titled test.txt.
-
Now let’s write
Hello World
in test.txt and re-upload it our bucket. -
In order to browse the two versions of test.txt, do one of the following:
i. Single click the file, click Latest version, and select the desired version from the drop-down menu and press Download.
ii. Switch the Versions slider to Show, you will now see two entries under test.txt, download whichever version is required.
Static Website Hosting
-
Let’s first create an HTML file titled index.html with the following contents:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <h1> Hello world! </h1> </html>
-
Upload index.html to the bucket.
-
From the bucket homepage, navigate to Properties.
-
Check the Use this bucket to host a website combo box.
-
In the Index document field, select index.html.
-
In the Error document field, select an HTML file that you want to serve in case of an error, if you did not create an error file, select index.html.
-
Note down the Endpoint URL.
-
Click Save.
-
Visit the endpoint URL to view the hosted website!