Saying hello to DynamoDB, Cognito, and Serverless
So since I've started dually learning some serverless application development using this awesome guide. I was able to skip through quite a few but they’re starting off with DynamoDB, which is awesome… because I’ve not used them before 😀 so I'm excited to see how it compares to the likes of MongoDB (Which I'll caveat with — been a while since I used that daily too).
What is Dynamo DB?
Amazon DynamoDB is a fast and flexible NoSQL database service for all applications that need consistent, single-digit millisecond latency at any scale. Its flexible data model and reliable performance make it a great fit for mobile, web, gaming, ad-tech, IoT, and many other applications.
I mean sure, you can pull out the facts from that elevator pitch but I’m a simple man, I like things said simply.
Paraphrasing it and https://www.dynamodbguide.com/ which I might add, is a great primer so far. They say…
DynamoDB is a hosted NoSQL database offered by Amazon Web Services (AWS). It offers:
- reliable performance even as it scales;
- a managed experience, so you won’t be SSH-ing into servers to upgrade the crypto libraries;
- a small, simple API allowing for simple key-value access as well as more advanced query patterns.
Show me the money
So you’re getting a feel for it now from a use case offering. It scales like a beast, it's easy to use (comparatively). Amazon thinks it’s worth using as per usual, they’re building for themselves and then sharing the love.
Amazon Prime Day 2020 - Powered by AWS | Amazon Web Services
Tipped off by a colleague in Denmark, I bought the LEGO Star Wars Stormtrooper Helmet, which turned out to be a Prime…
This year Amazon saw unprecedented traffic, maybe because we’re all stuck indoors avoiding COVID-19… but equally because they’ve made it so damn easy (too easy perhaps).
TL;DR — Over the course of the 66-hour Prime Day, things like Alexa and Amazon.com made 16.4 trillion calls to the DynamoDB API, peaking at 80.1 million requests per second.
That’s pretty damn impressive… a lot of that performance will come from two things to me.
- It scales so well and they can scale as much as they want — they own it
- They used it for the right things, one of the use cases was ‘Data sets with simple, known access patterns.’ in this case recommendations to users.
This is not a how-to, this is going to be an experiences log
Setting up the DynamoDB
Create a DynamoDB Table
Amazon DynamoDB is a fully managed NoSQL database that we are going to use to power our serverless API backend…
Following this guide from here, this was all pretty simple. Following the guide I went a read a little from this site also :
I’ll admit I’ve skimmed this but it's simple enough.
Setting up Cognito
Create a Cognito User Pool
Amazon Cognito User Pool handles sign-up and sign-in functionality for web and mobile apps. We are going to create a…
Cognito is going to be my identity equivalent, a user authentication. Just using it on a simple example I can already tell I’ll like this.
Amazon Cognito lets you add user sign-up, sign-in, and access control to your web and mobile apps quickly and easily. Amazon Cognito scales to millions of users and supports sign-in with social identity providers, such as Facebook, Google, and Amazon, and enterprise identity providers via SAML 2.0.
Makes me wonder why I’d never heard of it before, typically the likes of https://auth0.com/ had made it into my list of managed auth but not this. They feel similar so far.
Disclaimer: To date, I’ve only set up a user pool and created a user via the CLI.
Setup Serverless and added one endpoint
Set up the Serverless Framework
To create our serverless backend API using AWS Lambda and API Gateway, we are going to use the Serverless Framework…
A couple of deviations from the tutorial here:
- I used the Typescript edition of the serverless starter — https://github.com/AnomalyInnovations/serverless-typescript-starter.
- I had to do some hoop-jumping because of the fact I had multiple profiles on my AWS CLI already.
As a note for the future, be careful with serverless and profiles… it can trip you up if you miss that part about making sure you define it as
AWS_PROFILE . Also never assume you didn’t make a mistake copy-pasting it, I certainly did, that was 30 minutes of confusion I’ll never get back.
Wrapping up here… next is to flesh out more of the API and hopefully deploy it.