Most server-side-related apps require data to be stored on the server. AWS Mobile provides the means to configure a NoSQL account and access it from the app. Learn how the framework provides the functionality to create, read, update and delete (CRUD) data from the app to the server, and the app can also perform queries on the server.
- [Instructor] So now we're gonna move on to the next big area of the Mobile AWS features that we're gonna be adding to our project. We're gonna move on to add a NoSQL Database that our app can write to and read from. So the first thing we're gonna do is enable that on the console for our project. That'll create the base configuration necessary for us to then create a table and name it. That table will be mapped to a model that AWS will generate code for us from. We can then download that code and use it right in our project to read and write data to and from a database on AWS.
So the first thing we'll do is we'll go back to our console in our project and enable the NoSQL database. Then we'll add a table and any attributes we might want. Then we'll download the new configuration and the model and integrate that into our project. So back at the Mobile Hub, we're in our Notes project, and we can see our iOS app. We scroll down, we see the Backend that we already have configured. And now we're gonna add the NoSQL database. So I click on that and I click on Enable NoSQL.
Now I can add a table. When I click Add Table, it gives me a few options. I can base it on an example table, a custom table, or walk me through the creation process. We're gonna start with an example. So there's several different examples here. News for articles. There's one for Locations, Ratings, and so forth. We're gonna pick Notes. If we look at the table as it is, we can modify it if necessary. The permissions are private, so only the owner can read and write the item. I don't want anybody else reading my notes, so I want it to be private.
The partition key will be based on the userId. This means for a given user, we'll be able to access all their notes with a single query based on this partition. The Sort key will be the noteId. So now to identify an individual note for a user, we use the noteId and we can get everything else that we need. We have a couple other attributes. We have the content, the creation Date, and the title of a note. And that's fine for us for now, but if we wanted to, we could add more attributes. And then we have some examples down here of how to query and the indexing.
The only thing I want to change is the name of this table. Instead of Notes, I want it to just be Note. And that's because of the code that it'll generate later. I want the naming to jut be a single Note. So now I'll create the table. It gives me some information about that and I continue. Once again, when it's done, we have the banner saying that we need to update our configuration. I click on the flashing Integrate button and I download a new configuration.
Again I still have previously named AWS configuration files, so now the new one is dash three. But also notice that we have a section for downloading models. We're gonna download the Swift Model. So I click on that. It'll generate the model code and download that as well. Now I click on Next. I can see some walkthrough processes or click Done and be done. So the last thing I need to do is include that new configuration in my Xcode project and the code as well.
So back in Xcode, I'm gonna delete the current configuration and I'll right click on Notes to Add Files to Notes to add the new configuration. I go to Download and I add awsconfiguration-3. I'll rename that to remove the dash three. And I can also notice the new additions. It's using the Dynamo database, so now I have a Dynamo DB Object Mapper.
I also want to add the model that we downloaded, so I'll Add New Files to Notes. Downloads again, and drill down into the Amazon AWS models. Now that should be in my code with the note. And I've got the code to send and receive data to and from AWS Dynamo DB. So we enabled NoSQL database on our project, we added a table where we specified the name Note, and we inspected the attributes and permissions.
If we wanted to, we could have added more attributes, but for now those were fine with us. Then we downloaded the model and the new configuration file and integrated those into our project.
- AWS Mobile introduction
- Create your app project
- Adding authentication
- Adding Facebook and Google logins
- Configure data and file storage
- Reading, updating, deleting, and querying data
- Uploading, downloading, and deleting files