Chapter 4: The Three API Action Types

You usually interact with DynamoDB by using the AWS SDK or a third-party library in your programming language of choice. These SDKs expose a few API methods to write to and read from your DynamoDB table.

Well lets start using the AWS SDK to add a message to the DynamoDB Table.

Enter any message and click the "Add Message" button. This message will get saved in your DyanmoDB table.

For the message to get saved in your table, you must complete the steps in requirements chapter.

Refer the code below: This is a high level overview of using the AWS SDK and the DynamoDB Client to save a message in the table.


          import { PutCommand } from "@aws-sdk/lib-dynamodb";
          import ddbDocClient from "@/lib/clients/dynamoDBClient";
          import { dbName } from "@/lib/constants";

          const dbCommand = new PutCommand({
              TableName: dbName,
              Item: {
                pk: "message",
                sk: "MESSAGE#1",
                message: requestBody.message,
              },
          });

          const dbResponse = await ddbDocClient.send(dbCommand);
        

If you looking for an in-depth understanding of how we added the message to the table, refer to the following file-path.


          src/app/api/message/route.ts
        

In this chapter, we’ll learn about the core API actions with DynamoDB. The API for DynamoDB is small but powerful. This makes it easy to learn the core actions while still providing a flexible way to model and interact with your data.

1: Item-based actions

2: Queries

3: Scans

The API actions are divided based on what you’re operating on. Operating on specific items? Use the item-based actions. Operating on an item collection? Use a Query. Operating on the whole table? Use a Scan.