Creating a DynamoDB Table and Setting Up IAM Access Control
Published: 2024-07-08 18:33:40

**_Introduction to DynamoDB Tables_**
Amazon DynamoDB is a fully managed NoSQL database service provided by AWS (Amazon Web Services). It offers high performance, seamless scalability, and low latency for applications needing consistent, single-digit millisecond response times. DynamoDB is particularly well-suited for applications requiring fast and predictable performance with seamless scalability.

**_Architecture:_**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t0a9pu1g6rrn1hhbs67o.png)

**_Step 1:Create a DynamoDB table for student details _**

Navigate to the DynamoDB dashboard and click “Create table”, as show below. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ml1qk453hs4a9ap0vpun.jpg)

- When creating your DynamoDB table, you need to choose a name for the table and specify a Partition key.

- The Partition key determines the partition in which the data is stored, while the Sort key helps in sorting the data within the partition based on its value.

- Once you have named your table and assigned a partition key, navigate to the “Table settings” section.

- simply click the “Create table” button in orange to initiate the table creation process

**_Step2 :Add items to DynamoDB table_**

Choose your recently created table from the list. In the left panel, click on “Explore items” and then select “Create item” to begin creating a new item within the table.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6uhu912vp4u4hyqaqg75.jpg)
We are adding 6 student detail to the table.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2cp7gyw50kn9gy5ja181.jpg)
**_Step 3: Launch EC2 with IAM role to scan DynamoDB table_**
Launching an EC2 instance with an IAM role that allows it to scan a DynamoDB table involves several steps, including creating an IAM role with appropriate permissions, launching the EC2 instance with that IAM role, and writing code on the EC2 instance to interact with DynamoDB. 

In the next screen, give your role a name and click “Create role.”
**_step 4: Attach Policy_**

In the permissions tab, click "Attach policies directly".

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cqjpj6ymnbcpl2nsr74h.jpg)


Search for and attach the AmazonDynamoDBReadOnlyAccess policy (or create a custom policy with specific dynamodb:Scan permissions).

**_Step 5: Use the AWS CLI in the EC2 instance to scan the DynamoDB table_**
Navigate to the EC2 dashboard, then select your EC2 Instance.Then connect into your EC2 Instance by selection one of these ways:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2lov845s0sa5sx29pqnh.png)
I selected EC2 Instance Connect. We are now connected to our instance and ready to scan the table using the following command.

```
aws dynamodb scan --table-name <table_name> --region <region_name>

```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l3eg3moutslf9cqes730.jpg)
**_Benefits:_**

_Scalability_: DynamoDB scales automatically to handle any amount of traffic and storage.

_Performance_: Provides single-digit millisecond latency for read and write operations.

_Security_: IAM enables granular access control to DynamoDB resources, enhancing security posture.

**_Conclusion:_**
Setting up a DynamoDB table and configuring IAM access control ensures your application’s data storage is scalable, performant, and secure. By following best practices in defining table schemas, creating IAM policies, and integrating services, you establish a robust foundation for building cloud-native applications on AWS. This architecture supports modern application requirements with flexibility and resilience in data management.