

# Building data models with NoSQL Workbench
Data modeler

You can use the data modeler tool in NoSQL Workbench for Amazon DynamoDB to build new data models, or to design models based on existing data models that satisfy your application data access patterns. The data modeler includes a few sample data models to help you get started.

**Topics**
+ [

# Creating a new data model
](workbench.Modeler.CreateNew.md)
+ [

# Importing an existing data model
](workbench.Modeler.ImportExisting.md)
+ [

# Editing an existing data model
](workbench.Modeler.Edit.md)
+ [

# Adding sample data to a data model
](workbench.Modeler.AddData.md)
+ [

# Adding and validating access patterns
](workbench.Modeler.AccessPatterns.md)
+ [

# Importing sample data from a CSV file
](workbench.Modeler.ImportCSV.md)
+ [

# Facets
](workbench.Modeler.Facets.md)
+ [

# Viewing all tables in a data model using aggregate view
](workbench.Modeler.AggregateView.md)
+ [

# Exporting a data model
](workbench.Modeler.ExportModel.md)
+ [

# Committing a data model to DynamoDB
](workbench.Modeler.Commit.md)

# Creating a new data model
Creating a new model

Follow these steps to create a new data model in Amazon DynamoDB using NoSQL Workbench.

**To create a new data model**

1.  Open NoSQL Workbench, and on the main screen, select **Create model manually**. 

    A new page will open with an empty configuration for your first table. NoSQL Workbench creates all new data models with a default name (i.e. untitled-2) and adds them to the **Drafts** project folder. 

1.  On **Table configuration screen**, specify the following: 
   +  **Table name** — Enter a unique name for the table. 
   +  **Partition key** — Enter a partition key name, and specify its type. Optionally, you can also select a more granular data type format for sample data generation. 
   +  If you want to add a **Sort key**, specify the sort key name and its type. Optionally, you can select a more granular data type format for sample data generation. 
**Note**  
 To learn more about primary key design, designing and using partition keys effectively, and using sort keys, see the following:   
 [Primary key](HowItWorks.CoreComponents.md#HowItWorks.CoreComponents.PrimaryKey) 
 [Best practices for designing and using partition keys effectively in DynamoDB](bp-partition-key-design.md) 
 [Best practices for using sort keys to organize data in DynamoDB](bp-sort-keys.md) 

1. You can add other attributes to more clearly validate your model and access patterns. To add other attributes:
   +  Choose **Add an attribute**. 
   +  Specify the attribute name and its type. 
   +  Optionally, you can select a more granular data type format for sample data generation. 

1.  If you want to add a global secondary index, choose **Add global secondary index**. Specify the **Global secondary index name**, **Partition key** attribute, and **Projection type**. 

   For more information about working with global secondary indexes in DynamoDB, see [Global secondary indexes](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html).

1.  Optionally, **Add a facet**. A facet is a virtual construct in NoSQL Workbench. It is not a functional construct in DynamoDB. Facets in NoSQL Workbench help you visualize an application's different data access patterns for DynamoDB with only a subset of the data in a table. 
**Note**  
 We recommend you use [Adding and validating access patterns](workbench.Modeler.AccessPatterns.md) to visualize how your application will access data in DynamoDB instead of Facets. Access patterns mirror your actual database interactions and help you build the correct data model for your use case, while facets are non-functional visualizations. 

    Choose **Add facet**. Specify the following: 
   +  The **Facet name**. 
   +  A **Partition key alias** to help distinguish this facet view. 
   +  A **Sort key alias** if you provided a **Sort key** for the table. 
   +  Choose the **Attributes** that are part of this facet. 

    Repeat this step if you want to add more facets. 

1.  Finally, click the **Save** button to create the table. 

1.  If you need other **Tables** or **Global Secondary Indexes**, click on the **\$1** icon above the table you just created. 

# Importing an existing data model
Importing an existing model

You can use NoSQL Workbench for Amazon DynamoDB to build a data model by importing and modifying an existing model. You can import data models in either NoSQL Workbench model format or in [AWS CloudFormation JSON template format](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html).

**To import a data model**

1.  Open NoSQL Workbench, and on the main screen, select **Import model**. You can import either a NoSQL Workbench model format or CloudFormation JSON template. 

1.  You can add the imported model to an existing project or create a new project. If you don't choose a different project, your model will be added to the drafts project folder. 

1.  Click **Browse your desktop** and choose a model to import from your computer. 

# Editing an existing data model
Editing an existing model

**To edit an existing model**

1. To begin making changes to an existing model, open the model in the modeler page.

1. In the resource selector panel, you will see the list of **Tables** and **Global Secondary Indexes**.

1. To edit a **Table** or a **Global Secondary Index**, first click its name in the resource selector panel, and then use the action icons at the top. Available actions are **Delete**, **Duplicate**, and **Edit**.

1. If you want to edit **Model details**, click the three-dot icon next to the model name.

1. From there, you can click **Edit model details** and edit the information accordingly.

1. You can also **Duplicate**, **Move**, **Delete**, and **Export** the model from the same menu.

1. To change to another model, you can either go through the main screen again, or use the model selection dropdown. 

# Adding sample data to a data model
Adding sample data

**To auto-generate sample data**

1. Open NoSQL Workbench, and on the main screen, click the name of the model that you want to add sample data to.

1. Click the additional actions (three-dot icon) in the main content toolbar and select **Add sample data**.

1. Enter the number of items of sample data that you would like to generate, then select **Confirm**.

1. Auto-generating sample data helps you generate between 1 to 5000 rows of data for immediate use. You can specify a granular sample data type to create realistic data based on your design and testing needs. To utilize the capability to generate realistic data, you need to specify the sample data type format for your attributes in the Data modeler. See [Creating a new data model](workbench.Modeler.CreateNew.md) for specifying sample data type formats.

**To add sample data one item at a time**

1. Open the model you wish to edit then choose the table you want to add sample data to. Click the additional actions (three-dot icon) in the main content toolbar and select **Edit data**.

1. Now you can add, delete, and edit rows. After you have made necessary changes, click the **Save** button.

# Adding and validating access patterns
Adding and validating access patterns

You can use NoSQL Workbench for Amazon DynamoDB to create, store, and validate *access patterns*.

**Note**  
 See [Identify your data access patterns](https://docs.aws.amazon.com/prescriptive-guidance/latest/dynamodb-data-modeling/step3.html) for more details on identifying the right access patterns. 

**To create an access pattern**

1.  Open NoSQL Workbench, and on the main screen, click the name of the model that you want to add access patterns to. 

1.  On the left side, choose the **Access patterns** tab, and click the **\$1** icon. 

1.  On the next screen, provide a **Name**, an optional **Description**, the **Type** of the access pattern, and the **Table** or **Global Secondary Index** to test the access pattern against. 
**Note**  
 NoSQL Workbench currently supports the following operations for access patterns: `Scan`, `Query`, `GetItem`, `PutItem`, `UpdateItem`, `DeleteItem`. Amazon DynamoDB supports a broader list of operations. 

1.  After you create an access pattern, you can switch to the **Validate** tab to verify that your data model is designed to return expected results for the access pattern. See [Adding sample data to a data model](workbench.Modeler.AddData.md) for details on how to auto-generate sample data for your tables. Different types of access patterns will support different input parameters. 
**Note**  
To validate access patterns, NoSQL Workbench starts a separate DynamoDB local database on port `8001` (by default) with tables and indexes stored in memory.  
NoSQL Workbench automatically adds the sample data from your model to the temporary tables.
If you edit the sample data or the data model itself, NoSQL Workbench will update the temporary tables.
This temporary database is erased when you close the application.

**To edit your access patterns**

1.  Open NoSQL Workbench, and on the main screen, click the name of the model that you want to edit access patterns for. 

1.  On the left side, choose the **Access patterns** tab. 

1. To edit an access pattern, select it from the list on the left.

1. In the top bar, click the **Edit** action button.

# Importing sample data from a CSV file
Importing from CSV

If you have preexisting sample data in a CSV file, you can import it into NoSQL Workbench. This enables you to quickly populate your model with sample data without having to enter it line by line.

The column names in the CSV file must match the attribute names in your data model, but they do not need to be in the same order. For example, if your data model has attributes called `LoginAlias`, `FirstName`, and `LastName`, your CSV columns could be `LastName`, `FirstName`, and `LoginAlias`.

You can import up to 150 rows at a time from a CSV file.

**To import data from a CSV file into NoSQL Workbench**

1. To import CSV data to a **Table**, first click the table name in the resource panel, and then click the additional actions (three-dot icon) in the main content toolbar.

1. Select **Import sample data**.

1. Select your CSV file and choose **Open**. The CSV data appends to your table.

# Facets
Facets

 In NoSQL Workbench, *Facets* give you a way to view a subset of the data in a table, without having to see records that don't meet the constraints of the facet. Facets are considered a visual data modeling tool, and don't exist as a usable construct in DynamoDB, as they are purely an aid to modeling of access patterns. 

**Note**  
 We recommend you use [Adding and validating access patterns](workbench.Modeler.AccessPatterns.md) to visualize how your application will access data in DynamoDB instead of Facets. Access patterns mirror your actual database interactions and help you build the correct data model for your use case, while facets are non-functional visualizations. 

**To create a facet**

1. In the resource selector panel, choose a **Table** you wish to edit

1. In the top bar, click the **Edit** action icon.

1. Scroll down to the **Facet filters** section.

1.  Choose **Add facet**. Specify the following: 
   +  The **Facet name**. 
   +  A **Partition key alias** to help distinguish this facet view. 
   +  A **Sort key alias** if you provided a **Sort key** for the table. 
   +  Choose the **Attributes** that are part of this facet. 

    Repeat this step if you want to add more facets. 

# Viewing all tables in a data model using aggregate view
Aggregate view

The aggregate view in NoSQL Workbench for Amazon DynamoDB allows you to visualize all the tables and indexes in a data model. For each table, the following information appears:
+ Table column names
+ Sample data
+ All global secondary indexes that are associated with the table. NoSQL Workbench displays the following information for each index:
  + Index column names
  + Sample data

**To view all table information**

1. Open NoSQL Workbench, and on the main screen, click the name of the model that you want to open.

1. In the top bar, click **Aggregate view**. You will see the data across all tables and indexes on the same screen.

**To export aggregate view as images**

1. With **Aggregate view** selected, click the three-dot icon and choose **Export aggregate view**

1. An archive with PNG images of all tables and indexes will be presented for download.

# Exporting a data model
Exporting a model

After you create a data model using NoSQL Workbench for Amazon DynamoDB, you can save and export the model in either NoSQL Workbench model format or [AWS CloudFormation JSON template format](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html).

**To export a data model**

1. Open NoSQL Workbench, and on the main screen, click on the name of the model that you want to edit.

1. Click the three-dot icon next to the data model name and select **Export model**.

1.  Choose whether to export your data model in NoSQL Workbench model format or CloudFormation JSON template format. 
   +  Choose **NoSQL Workbench model** format if you want to share your model with other team members using NoSQL Workbench or import it into NoSQL Workbench later. 
   +  Choose **CloudFormation JSON template** format if you want to deploy your model directly to AWS or integrate it into your infrastructure-as-code workflow. 

# Committing a data model to DynamoDB
Committing a data model

 When you are satisfied with your data model, you can commit the model to Amazon DynamoDB. 

**Note**  
This action creates server-side resources in AWS for the tables and global secondary indexes represented in the data model.
NoSQL Workbench creates tables and indexes with on-demand capacity by default.

**To commit the data model to DynamoDB**

1. Open NoSQL Workbench, and on the main screen, click on the name of the model that you want to commit.

1. In the top bar, click **Commit**.

1. Choose an existing connection, or create a new connection by clicking the **Add new connection** button.
   + To add a new connection, specify the following information:
     + **Account Alias**
     + **AWS Region**
     + **Access key ID**
     + **Secret access key**

     For more information about how to obtain the access keys, see [Getting an AWS access key](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SettingUp.DynamoWebService.html#SettingUp.DynamoWebService.GetCredentials).
   + You can optionally specify the following:
     + [https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html)
     + [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-arns](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-arns)

1. If you prefer to use [DynamoDB local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html):

   1. Choose the **Local connection** tab.

   1. Click the **Add new connection** button.

   1. Specify the **Connection name** and **Port**.
**Note**  
 To use DynamoDB local, you will need to turn it on by using the **DynamoDB local** toggle at the bottom left of the NoSQL Workbench screen. 

1. Click **Commit**.