In this video, Jeff Winesett creates a new DynamoDB table for application data storage. DynamoDB is a fully managed NoSQL database service and provides a persistence layer within a serverless architecture being built in this video.
- [Instructor] In order to test my Lambda function out, which performs operations on a DynamoDB table, I need to create a DynamoDB table on which it can operate. So let's do that. From the console, I can start typing in Dynamo, and I see Dynamo in the drop-down, I'll choose that. And here I am at the DynamoDB service homepage. I'll start with creating table. I'll give it a name, I'll call my table namethings, we're going to store things in it.
And I need to give it a partition key. This provides the primary key to the table. And I'm going to stick to a simple partition key in this case. A sort key can be added to the primary key to allow for further partitioning the data within the partition key. But at this point, I'll just keep this simple, and I'll just name it thingid. And I'll keep it as a string. The rest I can use the defaults, are just fine. Another thing real quick to point out is there is a tutorial for DynamoDB that will walk you through each step of creating a new table in the context of a specific scenario.
This is a nice feature for those new to DynamoDB. In this case I'll click create, and the table is being created. This can take a few minutes, so we need to wait for the table to be created before we can interact with it. Okay, there it is. So first of all, in order to test this out, I can add items directly into the table. So for this I can go to the items tab, and I can create an item. And all I have is a one attribute in this table right now, so let me just call the thingid of car.
Okay, now I've got a car in my things table, with a unique identifier of car. Now that my DynamoDB table is in place I could actually also test it out with the Lambda function that we created before. So if I go back over to services, and go to Lambda, choose the function that I've already created, I can go right in here to test. Okay, and in order to test this, I need to input the JSON that the function's expecting.
I've also included this little snippit in the exercise files, so let me delete that, and I'll add in what's needed here. It's expecting in an httpMethod, and to save something into the table that's POST. And it expects a body that's in a string, that was going to be parsed into JSON, so that's why the string looks like this, it specifies the table name, which we set up as things. And it specifies the item object, which just has one attribute, thingid, and I'm adding in the value lambdatest. So let's give this a go.
Scroll down here, and I can save and test. The test was successful. Let me scroll up here, okay. It gave me a 200 back, it tells me everything was good, now it should have saved that information lambdatest into the DynamoDB if it worked according to what the function's supposed to do, when it gets a post of that information, it should save information into the DynamoDB table. Let's check that out.
Going back to services, DynamoDB, click into the table that I'm interested in, my things table. I look at my items, and sure enough, lambdatest is there. So we do have our basic Lambda function working against the DynamoDB at least from Lambda to DynamoDB. Now what we need to do additionally, is test out the API Gateway. So let me go to the API Gateway. If I start to type in gateway, API Gateway.
And as you recall, since we set up a demo microservice blueprint when we set up Lambda, it expected the trigger to be Amazon API Gateway, and so we've got one created for us. So I can go in here. And from here I can click on the API Gateway that I have, the method right now is ANY, I can click on that. And here I'm provided a test option right here, so I can test out the API Gateway internally, just to make sure it's working against the Lambda function that it's invoking.
So let me click test, and I'm going to choose the POST method, because I want to save a new thing to our things table. The query string information, don't need to save for a post, it expects everything to be in the request body. So it's expecting in a request body that looks like this. I've also included this little snippit in the exercise files for you to use as well.
So again it's specifying the table name as things, and it's specifying the item object, with the one property that it has, thingid, and in this case I'm sending an API test. We did the Lambda test, now I'm going to test the API internally. I'll click test, and I get some information back. In this case again I get 200, nothing in the response, I haven't configured it to actually provide any information back in the response, but this is more or less success. So just to make sure, I can always go back into services, DynamoDB, look at the table that I've already created, things, go to my items, and there it is, apitest has been added.
So I've tested it directly from this console by adding an item directly, I added car, probably should have added console test. Then I added one from testing Lambda, which worked. Then I added one directly from testing the API internally. Another test would be to ensure that this is working externally. So one thing that I could use is like a cURL command from the command line. And additionally I could reconfigure the front-end application to point to the Gateway API, and that way I could get the front-end application, let me remind you what that looks like over here, that we did a couple videos back, actually working against this DynamoDB table.
And that's what I'm going to do next.
- Benefits of cloud services
- Making architectures scalable
- Examining cloud constraints
- Virtual servers, EC2, and Elastic IP
- Using the Amazon machine image
- Elastic load balancing
- Using CloudWatch for monitoring
- Security Models
- Elastic block storage
- S3, CloudFront, and Elastic Beanstalk
- Handling queues, workflows, and notifications
- Caching options and services
- Identity and access management
- Creating a custom server image
- Application deployment strategies
- Serverless architectures