Build a Serverless App with AWS Lambda – Hands On!
Immerse yourself in Amazon Web Services (AWS) with this hands-on, project-based course – and truly internalize some highly valuable skills in the world of technology. We’ll walk you through building your own chat website using nothing but AWS services – and no standalone services or server instances at all!
Building a “serverless app” using AWS and its Lambda service is a great introduction to the core services AWS offers. As you create your chat application, you’ll learn and use the following AWS services:
- S3 (Simple Storage Service) – For storing static HTML and vending it to your users’ browsers
- Lambda – For executing logic in the cloud for storing and retrieving data in your application
- IAM (Identity and Access Management) – For securing access to your services
- API Gateway – For presenting a well-modeled API to your clients and automatically generating client-side code to communicate with it
- DynamoDB – For quickly storing and retrieving data at scale
- Cognito – For managing users, account creation, and logins securely
- CloudFront – For accelerating the delivery of your site to end users with a CDN
Even if you’re familiar with AWS, you’ll learn valuable techniques on how to build a fully functional, dynamic website without maintaining any servers at all – not even via EC2!
Your highly experienced guides through this project are Frank Kane, formerly a senior manager at Amazon, and Brian Tajuddin, a principal engineer also formerly working at Amazon. You’ll be learning AWS from people who were there when it was being created. You’ll join over 140,000 other students of the Sundog Education team who have leveled up their careers with hot technical skills.
As an added bonus, you’ll be offered membership in a closed Facebook Group for students of this course, where you can continue to collaborate with each other even after you’ve finished it.
Although this course isn’t targeting any specific AWS certification exam, you’ll leave it with a great foundation of AWS knowledge that will begin to prepare you for them.
Course overview and demo of the chat application
Create an AWS account, an S3 bucket, upload a website, and view it in your browser
Static Chat Application with S3
Buckets, paths, and static website hosting
For now, we'll upload some static chat data into S3 in JSON format so we have something to display.
Let's dynamically modify our chat pages to include the static chat data we're vending from S3.
We'll walk through the previous lecture's challenge of adding a new message and a new conversation to our chats.
Creating an API
Learn how Lambda allows you to execute snippets of code without running a dedicated server.
Identity and Access Management lets you secure your services and the services they have access to.
Let's give our Lambda function the permissions it needs to read our data from S3.
Let's dissect our first Lambda function, and how it works.
Learn how to create a test case for our Lambda function, and run it from within the AWS console.
Triggers are what cause your Lambda function to be executed. Let's cover the various ways in which that can work.
Let's set up the API Gateway in Proxy mode to trigger our Lambda function when an API is called from our client.
Learn how Cross-Origin Resource Sharing (CORS) gets around browser security to allow you to call web services from your page.
Let's modify our client-side code to hit the API Gateway and Lambda, instead of S3 directly.
We'll walk through the previous lecture's challenge to break CORS support intentionally and see what happens, and to lock down our API to only be accessible to your S3 bucket.
Let's modify our app to retrieve entire conversations using the API Gateway.
We'll walk through our solution to the previous lecture's challenge of writing test cases for failure modes.
Use DynamoDB for storage
Let's cover DynamoDB from a high level, and learn how it might help us store our chat data more efficiently.
Why use DynamoDB instead of S3? There are pros and cons to each, but DynamoDB is the clear winner for us.
Create the tables we need for chat conversations and messages in DynamoDB
Populate our DynamoDB tables with some sample chats for us to test with.
Grant our Lambda function the necessary permissions via IAM to access our DynamoDB tables instead of S3.
Modify and test our application to read chat conversations from DynamoDB instead of S3.
Modify and test our application to read the conversation list from DynamoDB instead of S3.
Modify our chat application to allow users to enter new chat messages and store them in DynamoDB where others can see them!
We'll walk through our solution to the challenge of handling invalid HTTP methods, and removing the now unnecessary access to S3 from our Lambda functions.
Break up the monolith
Why go through the trouble of breaking up our monolithic Lambda function? Let's explain.
What are resources and methods in the API Gateway, and how are they used?
What models are in the API Gateway, and how to use them.
Dissecting the request flow diagram in the API Gateway.
Let's go hands on and define our API for our chat application in the API Gateway, not in proxy mode.
Let's split up our Lambda function into individual ones for reading and writing messages.
We'll cover stages in the API Gateway and how they are used.
We'll tackle the previous lecture's challenge of removing the hardcoded "Student" user name from our Lambda functions, and providing it as an event parameter instead.
Add Identity to the app
Let's cover the various components of Cognito, which we'll use for user account management.
Let's walk through Cognito in the console, and set up the user pool for our chat application.
Next we need to wire things up for listing users through Lambda with an associated IAM policy and role, and through the API Gateway.
Let's add the front-end code for listing users - and dive into how to debug things when things don't work.
Let's wire up the API and front end for creating a new conversation.
Let's create a working sign up page so new users can create accounts.
Now we need to wire up a page so users can enter the authentication code they received via email, or request it to be re-sent.
Now that we can sign in and confirm users, let's actually sign them in and tie their identity into the rest of the app.
We need to reconfigure the API Gateway to use an Authorizer, and modify our input mappings to use the new authenticated user.
We have sign in and authorization on the API, and now we just need to link the two together!
In the last lecture, we challenged you to fix the problem of starting chats with yourself, and to ensure you can't see chats that you're not involved in. Let's look at our solution.
Optimization and Preparing for Production
You don't want your changes to "go live" immediately. Lambda versioning ensures a known good version of what your code is what's live. We'll also use Canary to divide traffic between different deployments, create and use a test stage and promote it to production, and use version aliases to simplify the configuration of Lambda.
Let's see how Stage Variables can let us maintain separate databases, or resources in general, between different stages so they don't pollute each other.
Let's talk about how CloudFront, AWS's content delivery network, works and why it's important.
Let's walk through setting up CloudFront to accelerate the delivery of our static resources in S3.
We'll tour the various monitoring available in AWS for our application, and practice setting up an alarm.
Finally, let's walk through how you would go about associating your own custom domain name with this application. We'll also show you how to associate a custom domain name with your API layer, if that's something you want to expose more widely.
You Made It! Where to go from here.
There's so much more learn about AWS! Here are some pointers for continuing your exploration.