Building a serverless website with S3

After working with Amazon Web Services for some time now I’m still amazed at the flexibility each solution holds. Out of all the services AWS houses the one I use the most is S3. S3 currently holds over 40 TB’s of data for me in a multi-tiered secure environment with multiple redundancy features in place. So what does that mean exactly? Essentially, my data is fairly secure and duplicated so I can make sure that my files never get lost even if an Amazon data center were completely lost.

What is S3: Simple Storage Solution

S3 Overview

  • Object based storage: Users can store flat files like word doc’s, videos, photos, pdf’s, etc.
  • Files can be from 0 bytes to 5TB in size: AWS provides unlimited storage
  • Files stored in Buckets that must be unique globally: Buckets are just Folders
  • Read after Write Consistency for PUTS of new objects and Eventual Consistency for overwrite PUTS and DELETES
  • Amazon offers a 99.99 Availability and 99.99999999% Durability Guarantee
  • S3 is designed to sustain a 2 facility loss without the loss of your data

How Can I Use S3

Amazon S3 is designed to be highly flexible. Users can store any type or amount of data they want.

What S3 is not

Running a serverless website

Bringing the Static

Nicolas Cage Minesweeper Game S3 Demo

Steps To Build

  1. Create a new bucket
  2. Name your bucket: Must be a globally unique name
  3. Set permissions to grant public read access
  4. Go to bucket’s properties and select static web hosting
  5. Enter the name of your index document. Mine was index.html
  6. Enter the name of your error / 404 page. I just entered the same index.html
  7. Upload all your HTML, CSS, and JS files to the bucket. It doesn’t matter if files are nested within folders everything will be read
  8. On the upload of your files, set permissions to grant public read access
  9. For the demo I left all other settings at default
  10. Get your endpoint(your url) inside of the static web hosting properties page
  11. That’s it your static application is live.

But Wait There’s More…

Lambda

AWS Lambda is an event-driven, serverless computing platform. Lambda is a compute service that runs code in response to events and automatically manages the compute resources required by that code. That means that you can run code without provisioning or managing servers. You pay only for the compute time you consume — there is no charge when your code is not running. Just upload your code and Lambda takes care of everything required to run and scale your code with high availability.

Going A Bit Deeper

Now that you have lambda doing processing for you how about we make an API call. That’s where AWS’s API Gateway comes in. It allows you to process hundreds of thousands of concurrent API calls and handles traffic management, authorization, access control, monitoring, and API version management.

DynamoDB

Do you need to persist data? Well they’ve got you covered on that front as well. DynamoDB is a fast and flexible NoSQL database service for all applications that need consistent, millisecond latency at any scale. It is a fully managed cloud database and supports both document and key-value store models. That means you can you can create database tables that can store and retrieve any amount of data, and serve any level of request traffic.

Weather App Reference Architecture

Want to see this implementation running? Feel free to go to my githubaccount here to see the entire code setup for the above example.

Conclusion

You get a hosted site with no server management needed, completely flexible scaling, built-in availability and fault tolerance. Did your head just explode? Probably, because serverless deployment really is that amazing. You don’t need to architect for any of the above capabilities since the services running the application provide them by default.

AWS even has an Application Repository where you’re able to find and deploy prebuilt serverless applications and application components for a variety of use cases, including web and mobile back-ends, chatbots, IoT, Alexa Skills, data processing, stream processing, and more. You can also find integrations with popular third-party services like Slack, Twilio, Sumo Logic, Box, and more.

You can read more about AWS Lambda and serverless computing on the AWS website here.

Originally published at Bryan Ortiz: The Digital Resume.