The underlying AWS mobile CLI used in this course has changed it's API. If you're starting to learn AWS, you may want to try the latest course. We now recommend you take the AWS for Front-End Engineers (ft. S3, Cloudfront & Route 53) course.

Check out a free preview of the full Rapid Development on AWS: React, Node.js & GraphQL course:
The "Adding Cloud API with Mobile Hub" Lesson is part of the full, Rapid Development on AWS: React, Node.js & GraphQL course featured in this preview video. Here's what you'd learn in this lesson:

Steve uses the cloud-api feature within AWS Mobile Hub CLI to create an API.

Get Unlimited Access Now

Transcript from the "Adding Cloud API with Mobile Hub" Lesson

>> Steve Kinney: The other thing we need is an API, so again, looking at this AWS mobile, we can see that cloud API looks like a pretty good choice. Cloud API again, is API gateway over lambda. Basically a http request hits the API gateway, then that triggers off the lambda and most likely the lambda will then put something in Dynamo DB, take something out of Dynamo DB, update something, delete something.

[00:00:29] So it's kind of all the way from our client side app, fires the http request. That hits the API gateway, triggers a lambda. The lambda does a thing. Right, the best part is you don't need to know any of that. So, will do awsmobile cloud-api enable.
>> Steve Kinney: Cool.

[00:00:59] Actually, I want to, I went into prompt cuz I want it to ask me about what I want it to do. So I'm just going to real quick, look at my awsmobile features.
>> Steve Kinney: I'm gonna turn that one off and try again. Nice part is I never deployed this code.

[00:01:21] I never pushed it. It was simply some configuration scenario machine that I haven't done anything with. So I made a booboo. Guess what? You can undo it really easily.
>> Steve Kinney: So we'll do --prompt.
>> Steve Kinney: All right, so we have two options. Create a new API. What kind of API?

[00:01:37] It doesn't really say, but this does mean that you can do custom stuff. If you have some other API that you want to talk to, you need some service-side code, because of course, or something along those lines, you want some backend code to talk to maybe a third-party API or something along those lines.

[00:01:50] You can just spin up a new API and write the JavaScript, yourself, to talk to that backend. But if you have a database table that you wan to work with, then you can simply say, create CRUD API for existing Amazon DynamoDB table, all right? And because we're keeping all of our configuration in code, it can look and it can see what the actual tables that we have available are for us.

[00:02:16] So in this case, we have the Grudges Table. We do want to restrict access to signed-in users. Our database was previously restricted, but our API wasn't, right? So in this case, in order to not get a forbidden from the API, we're going to say, you need to be signed in.

[00:02:36] Cool, and its going ahead and creating that for us.
>> Steve Kinney: That's gonna take a few seconds. So it does give you a way via the command line to take the API for a spin. This works better with the unrestricted API's. Because it's really I guess, you can go get a user ID and do it all on the command line here.

[00:03:00] It's actually very tricky to do. Even to be clear putting JSON in quotes, and then having double quotes on the inside on the command line, in the terminal as a one-liner, it's all fairly difficult. So I tend not to use this too much, but let's actually look at the AWS Mobile console again.

[00:03:24] Let's see what we have with the cloud API.
>> Steve Kinney: We gotta do an AWS Mobile push. No one caught me on that one. That was a test.
>> Steve Kinney: While that is loading, let's go take a look at that NoSQL database that was still spinning before. We can go ahead and we can hit edit.

[00:03:49] We can see it's private, we can also see all of our different fields so if you made some kind of mistake or a typo in this case, you can go ahead and fix it in the UI as well. You can remove keys with that yes or no question.

[00:04:01] I'm like at a 25% chance that I either forgot a field or I hit yes and it's like what do you want to call that extra field? I'm like, nothing, I made a mistake. And you can either Ctrl+C and start all over again, or you can give it some foo name and delete it later.

[00:04:18] Whatever, it's totally fine. And basically, here you can see we can find items with a user ID and a given ID because we set that as that secondary sort key. Which is exactly what we want at this point. Cool, let's go check on this. This is gone ahead, and it's created.

[00:04:35] One of the things is, we'll take a look at the code that got generated next, but you can see the way it takes an entire backend API, zips it and sends it up to the Cloud. Let's take a look. This is just a server list node, a server list is obviously someone else's server just the way Cloud is somebody else's computer.

[00:04:56] So it's the same as server list per se. But the idea that you don't have to manage the server is awesome because managing the server is the literal worst. Actually, writing forgot password logic is the literal worse, but