How to Create a DynamoDB Table Using AWS Console
To create a DynamoDB table in the AWS Console, open the DynamoDB service, click
Create table, enter a Table name and Primary key, then configure settings like capacity mode and indexes before clicking Create. This sets up your table ready to store and retrieve data.Syntax
Creating a DynamoDB table in AWS Console involves these main parts:
- Table name: A unique name for your table.
- Primary key: Defines how items are uniquely identified. It can be a simple key (partition key) or composite key (partition key + sort key).
- Capacity mode: Choose between
On-demand(pay per request) orProvisioned(set read/write units). - Secondary indexes: Optional indexes to query data efficiently.
- Encryption and tags: Optional security and metadata settings.
text
Create table with: - Table name: string - Primary key: partition key (string or number), optional sort key - Capacity mode: On-demand or Provisioned - Optional: secondary indexes, encryption, tags
Example
This example shows how to create a DynamoDB table named Books with a partition key ISBN of type string, using On-demand capacity mode.
text
1. Sign in to AWS Management Console. 2. Open the DynamoDB service. 3. Click on 'Create table'. 4. Enter 'Books' as Table name. 5. Set Partition key as 'ISBN' with type 'String'. 6. Choose 'On-demand' for capacity mode. 7. Leave other settings as default. 8. Click 'Create table'.
Output
Table 'Books' is created and ready to use with On-demand capacity and primary key 'ISBN'.
Common Pitfalls
Common mistakes when creating DynamoDB tables include:
- Choosing a poor primary key that does not uniquely identify items, causing data overwrite.
- Using Provisioned capacity without estimating traffic, leading to throttling or extra costs.
- Forgetting to add secondary indexes when needed for queries, limiting data access patterns.
- Not enabling encryption if data security is required.
Always plan your keys and capacity based on your app needs.
text
Wrong: - Primary key: 'Category' (not unique) Right: - Primary key: 'OrderID' (unique per item)
Quick Reference
| Setting | Description | Example |
|---|---|---|
| Table name | Unique name for the table | Books |
| Partition key | Primary key attribute name and type | ISBN (String) |
| Sort key | Optional secondary key for sorting | Author (String) |
| Capacity mode | On-demand or Provisioned | On-demand |
| Secondary indexes | Optional indexes for queries | GSI on Author |
| Encryption | Enable encryption at rest | AWS owned CMK |
Key Takeaways
Use the AWS Console DynamoDB service to create tables with a clear table name and primary key.
Choose On-demand capacity mode for flexible billing or Provisioned for predictable workloads.
Plan your primary key carefully to avoid data conflicts and support your queries.
Add secondary indexes if you need to query data by attributes other than the primary key.
Enable encryption and tags for security and management best practices.