Check out a free preview of the full Build Go Apps That Scale on AWS course
The "DynamoDB" Lesson is part of the full, Build Go Apps That Scale on AWS course featured in this preview video. Here's what you'd learn in this lesson:
Melkey spends a few minutes discussing DynamoDB. It's a fully managed NoSQL database server that uses key-value stores. It's a fast, scalable database solution for serverless functions. A question about testing locally is also discussed in this lesson.
Transcript from the "DynamoDB" Lesson
[00:00:00]
>> All right, so I wanna start with the very first thing which is kinda the lowest layer, which is actually inserting users into the database and I wanna work our way up. So, I wanna get all the logic to insert users, go up to our API handler how we're gonna call those functions, and then route them into our main go file.
[00:00:18]
But before we do that, I think it's important to talk a little bit about what DynamoDB is, and for those who've used DynamoDB I think it's fair to say it's kinda polarizing you either really love it or you really like it. A lot of people at Amazon and at AWS obviously really like, it no surprise there.
[00:00:42]
But what DynamoDB is, it's a fully managed NoSQL database, and what that means is if you're familiar with Postgres or that kinda relational style, it doesn't have that there's no this column expects this value. That concept does not exist in DynamoDB, because it's a key value store, right?
[00:01:02]
That's simply just putting keys and has a value associated to it, but those values can be not just one it could be an array of values. So, you can input the width of your entry, the width of your row with all these different columns into DynamoDB without necessarily specifying the schema associated to that.
[00:01:21]
So you work with MongoDB, it's very similar Redis also fairly similar. So it's not that concept of a relational schema for DynamoDB, but there is one main constraint and there's a lot of different constraints, you have foreign key relationships you have different relationships. The main one is the primary key relationship or the main entry for the key in DynamoDB, cause this acts as the unique identifier for retrieving the items and for inserting items.
[00:01:49]
This is how we can have like, O1 speed with DynamoDB in theory, because we can map all the entries to one particular key that we can retrieve things by and insert good things by as well, okay. And this key this constraint key has to be unique. And in our case, that key is gonna use your names because we don't want multiple usernames, we didn't want like two to use the same username.
[00:02:12]
You can also concatenate different keys as well, so, you could be username plus something else that could act as one primary key, for our case we're gonna keep it simple. The main key is going to be the username, that's gonna help to see like, hey, there's this user already exists or not as well.
[00:02:28]
A lot of different things like it's fast, it's scalable, it really is fast and it does scale like a lambda, it's a really nice piece of infrastructure. And this diagram I thought was very kinda exactly what we're gonna do, we're gonna have our import data. So we're not importing anything necessarily, but we're gonna get JSON data from our clients, and then we're gonna take that JSON data.
[00:02:50]
We're gonna have some transformation logic, which is what our Lambda, our backend service is gonna do, and then we're gonna upload that data into DynamoDB. This process is more machinerized we gonna get a bunch of data, we gonna batch input, but we can do one by one through this diagram here, all right?
[00:03:05]
So TLDR, this is our database, our lambda function does some logic and we have a request coming in from our client. Yeah, question.
>> A bit more of a general question, but how do you test the lambdas and the database stuff locally?
>> Yeah, so testing locally is a I would say it's a difficult thing to do seamlessly.
[00:03:28]
It has a bit more of the initial investment to stop your local computer to test locally. There's different things to offer services that do that like SST being one of them. You can have like SAM stacks, deploying stuff, there's other opportunities to do local development with lambdas. It's just a bit of a trickier concept because you are deploying artifacts to the lambda function, you are trying to base connections with an actual DynamoDB client.
[00:03:54]
So testing locally is a bit of a pain point, but you can set up an environment to test locally as well.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops