In my previous blog post, I talked about the evolution of how we got to the serverless design pattern. In this blog post, I’ll deep dive into the specifics of the design pattern.
“Never let a good crisis go to waste.”Charles Doyle
When this COVID-19 pandemic started, I decided this was a good time to spend some time researching new technologies and not letting this crisis go to waste. I decided to challenge myself and create a full stack app during the pandemic, mind you I haven’t really programmed in 25 years! My goal was to create a dashboard that would allow a user to authenticate and then access an internal dashboard that used APIs to get data stored in a database.
With any serverless design pattern you need to think about three areas:
- Frontend – the UI of the app
- Backend – the business logic and database
- DevOps – the intersection of the developers and operations team to keep the application up and running
Today, I’m going to discuss DevOps and building the infrastructure. Another feature of serverless is called Infrastructure as Code (IAC), which is the provisioning of resources using a script or definition file. By using a script you can quickly build/provision the resources you need and also quickly tear them down. Since I’m using AWS, the language they use is called CloudFormation. Simply put, it’s a language used to generate a YAML file that provisions the required AWS resources. Just like any other AWS product there are multiple ways to interact and create that YAML file:
- Using the AWS Management Console – a good way to get started but the least recommended method
- AWS CLI (command line interface)
- AWS SAM (serverless application model) CLI
- AWS CDK (Cloud Development Kit) – the newest tool that uses familiar programming languages like TypeScript to build the CloudFormation file
- Serverless.com Framework – not from Amazon but open-source and used by many folks
After reviewing many of the tools, I decided to use the Serverless Framework, it’s an open source tool that allows you to create a CloudFormation template. Although the Serverless Framework focuses on the backend resources it does allow you to also deploy the frontend app as well, so through this tool it does the backend and frontend.
Using the Serverless framework, I was able to provision 5 of the 6 services used in the dashboard app:
S3 – where the front end app is copied to. Then it gets deployed to CloudFront content delivery network
CloudFront – the static files that are accessed via the web browser
API Gateway – public facing APIs that connect to the Lambda function
DynamoDB – database where all the data resides