Amazon DynamoDB Connector Example

Amazon DynamoDB Connector allows you to access the Amazon DynamoDB REST API from an integration sequence.

What you'll build

Given below is a sample scenario that demonstrates how to work with the Amazon DynamoDB Connector and how to perform various table and items operations with Amazon DynamoDB.

This example explains how to use Amazon DynamoDB Connector to:

  1. Create a table (a location for storing employee details) in Amazon DynamoDB.
  2. Insert employee details (items) in to the created table.
  3. Update employee details table.
  4. Retrieve information about the inserted employee details (items).
  5. Remove inserted employee details (items).
  6. Retrieve list of tables.
  7. Remove created employee details table.

All seven operations are exposed via an API. The API with the context /resources has seven resources

  • /addtable : Creates a new table in the Amazon DynamoDB with the specified table name to store employee details.
  • /insertdetails : Insert employee data (items) and store in the specified table.
  • /updatetable : Update specified table (provisioned throughput settings, global secondary indexes, or DynamoDB Streams settings for a specified table).
  • /listdetails : Retrieve information about the added employee details (items).
  • /deletedetails : Remove added employee details from the specified table (items).
  • /listtable : Retrieve information about the created tables.
  • /deletetable : Remove created table in the Amazon DynamoDB.

For more information about these operations, please refer to the Amazon DynamoDB connector reference guide.

Note: Before invoking the API, you need to configure message builders/formatters in deployment.toml. See Setting up the Amazon DynamoDB Connector documentation for more information.

The following diagram shows the overall solution. The user creates a table, stores some employee details (items) into the table, and then receives it back. To invoke each operation, the user uses the same API.

Amazon DynamoDB connector example

If you do not want to configure this yourself, you can simply get the project and run it.

Configure the connector in WSO2 Integration Studio

Connectors can be added to integration flows in WSO2 Integration Studio. Once added, the operations of the connector can be dragged onto your canvas and added to your resources.

Import the connector

Follow these steps to set up the Integration Project and the Connector Exporter Project.

  1. Open WSO2 Integration Studio and create an Integration Project. Creating a new Integration Project

  2. Right-click the project that you created and click on Add or Remove Connector -> Add Connector. You will get directed to the WSO2 Connector Store.

  3. Search for the specific connector required for your integration scenario and download it to the workspace. Search Connector in the Connector Store

  4. Click Finish, and your Integration Project is ready. The downloaded connector is displayed on the side palette with its operations.

  5. You can drag and drop the operations to the design canvas and build your integration logic. Drag connector operations

  6. Right click on the created Integration Project and select New -> Rest API to create the REST API.

Add integration logic

First create an API, which will be where we configure the integration logic. Right click on the created Integration Project and select, New -> Rest API to create the REST API. Specify the API name as amazonDynamoDBAPI and API context as /resources.

Adding a Rest API

Configuring the API

Now follow the steps below to add resources to the API.

Configure a resource for the addtable operation

  1. Initialize the connector.

    1. Navigate into the Palette pane and select the graphical operations icons listed under Amazondynamodb Connector section. Then drag and drop the init operation into the Design pane.

      Drag and drop init operation

    2. Add the property values into the init operation as shown below. Replace the region, accessKeyId, secretAccessKey, blocking with your values.

    3. region : The region of the application access.

    4. accessKeyId : The AWS secret access key.
    5. secretAccessKey : The AWS accessKeyId of the user account to generate the signature.
    6. blocking : Boolean type, this property helps the connector perform blocking invocations to AmazonDynamoDB.

      Add values to the init operation

  2. Set up the createTable operation.

    1. Navigate into the Palette pane and select the graphical operations icons listed under Amazondynamodb Connector section. Then drag and drop the createTable operation into the Design pane.

      Drag and drop create table operation

    2. The createTable operation creates a new table. Table names must be unique within each region. The createTable operation parameters are listed here.

    3. attributeDefinitions : A list of attributes that describe the key schema for the table and indexes. If you are adding a new global secondary index to the table, AttributeDefinitions should include the key element(s) of the new index.

    4. tableName : The name of the table to create.
    5. keySchema : Specifies the attributes that make up the primary key for a table or an index. The attributes in keySchema must also be defined in attributeDefinitions.
    6. localSecondaryIndexes : One or more local secondary indexes (the maximum is five) to be created on the table. Each index is scoped to a given partition key value. There is a 10 GB size limit per partition key value. Alternately, the size of a local secondary index is unconstrained.
    7. provisionedThroughput : Represents the provisioned throughput setting for a specified table or index.

      While invoking the API, the above five parameter values come as a user inputs.

      Drag and drop create table operation

    8. To get the input values in to the API we can use the property mediator. Navigate into the Palette pane and select the graphical mediators icons listed under the Mediators section. Then drag and drop the Property mediators into the Design pane as shown below.

      Add property mediators

      The parameters available for configuring the Property mediator are as follows:

      Note: That the properties should be add to the pallet before create the operation.

    9. Add the property mediator to capture the attributeDefinitions value.

    10. name : attributeDefinitions

    11. expression : json-eval($.attributeDefinitions)

      Add property mediators attributeDefinitions

    12. Add the property mediator to capture the tableName values.

    13. name : tableName

    14. expression : json-eval($.tableName)

      Add values to capture tableName

    15. Add the property mediator to capture the keySchema values.

    16. name : keySchema

    17. expression : json-eval($.keySchema)

      Add values to capture keySchema

    18. Add the property mediator to capture the localSecondaryIndexes values.

    19. name : localSecondaryIndexes

    20. expression : json-eval($.localSecondaryIndexes)

      Add values to capture localSecondaryIndexes

    21. Add the property mediator to capture the provisionedThroughput values.

    22. name : provisionedThroughput

    23. expression : json-eval($.provisionedThroughput)

      Add values to capture provisionedThroughput

Configure a resource for the insertdetails operation

  1. Initialize the connector.

You can use the same configuration to initialize the connector. Please follow the steps given in 1.1 for setting up the init operation to the addtable operation.

  1. Set up the putItem operation.

    1. Navigate into the Palette pane and select the graphical operations icons listed under Amazondynamodb Connector section. Then drag and drop the putItem operation into the Design pane.

      Drag and drop put items operation

    2. The putItem operation use to insert new items to the tables. putItem operation parameters listed here.

    3. item : A map of attribute name/value pairs, one for each attribute. Only the primary key attributes are required, but you can optionally provide other attribute name-value pairs for the item

    4. tableName : The name of the table to contain the item.

      While invoking the API, the above two parameter values come as a user inputs.

      Drag and drop put items table operation

    5. Then drag and drop the Property mediators into the Design pane as mentioned in addtable operation. The parameters available for configuring the Property mediator are as follows.

    Add the property mediator to capture the item value.

    • name : item
    • expression : json-eval($.item)

      Add property mediators to capture item

    • Add the property mediator to capture the tableName values. Please follow the steps given in addtable operation.

    • name : tableName

    • expression : json-eval($.tableName)

Configure a resource for the updatetable operation

  1. Initialize the connector.

You can use the same configuration to initialize the connector. Please follow the steps given in 1.1 for setting up the init operation to the addtable operation.

  1. Set up the updateTable operation.

    1. Navigate into the Palette pane and select the graphical operations icons listed under Amazondynamodb Connector section. Then drag and drop the updateTable operation into the Design pane.

      Drag and drop put items operation

    2. The updateTable operation is used to update the created tables. The updateTable operation parameters are listed here.

    3. provisionedThroughput : The new provisioned throughput setting for the specified table or index.

    4. tableName : The name of the table to contain the item.

      While invoking the API, the above two parameter values come as a user inputs.

      Drag and drop put items table operation

    5. Then drag and drop the Property mediators into the Design pane as mentioned in the addtable operation. The parameters available for configuring the Property mediator are as follows.

    Add the property mediator to capture the provisionedThroughput value.

    • name : provisionedThroughput
    • expression : json-eval($.provisionedThroughput)

      Add property mediators to capture provisionedThroughput

    • Add the property mediator to capture the tableName values. Please follow the steps given in addtable operation.

    • name : tableName

    • expression : json-eval($.tableName)

Configure a resource for the listdetails operation

  1. Initialize the connector.

You can use the same configuration to initialize the connector. Please follow the steps given in 1.1 for setting up the init operation to the addtable operation.

  1. Set up the getItem operation.

    1. Navigate into the Palette pane and select the graphical operations icons listed under Amazondynamodb Connector section. Then drag and drop the getItem operation into the Design pane.

      Drag and drop get items operation

    2. The getItem operation is used to retrieve inserted items to the tables. The getItem operation parameters are listed here.

    3. key : An array of primary key attribute values that define specific items in the table. For each primary key, you must provide all of the key attributes.

    4. tableName : The name of the table to contain the item.

      While invoking the API, the above two parameter values come as a user inputs.

      Drag and drop put items table operation

    5. Then drag and drop the Property mediators into the Design pane as mentioned in addtable operation. The parameters available for configuring the Property mediator are as follows.

    Add the property mediator to capture the key value.

    • name : key
    • expression : json-eval($.key)

      Add property mediators to capture key

    • Add the property mediator to capture the tableName values. Please follow the steps given in addtable operation.

    • name : tableName

    • expression : json-eval($.tableName)

Configure a resource for the deletedetails operation

  1. Initialize the connector.

You can use the same configuration to initialize the connector. Please follow the steps given in 1.1 for setting up the init operation to the addtable operation.

  1. Set up the deleteItem operation.

    1. Navigate into the Palette pane and select the graphical operations icons listed under Amazondynamodb Connector section. Then drag and drop the deleteItem operation into the Design pane.

      Drag and drop get items operation

    2. The deleteItem operation is used to remove inserted items from the table. The deleteItem operation parameters are listed here.

    3. key : An array of primary key attribute values that define specific items in the table. For each primary key, you must provide all of the key attributes.

    4. tableName : The name of the table to contain the item.
    5. returnConsumedCapacity : Determines the level of detail about provisioned throughput consumption that is returned in the response.
    6. returnValues : Use returnValues if you want to get the item attributes as they appeared before they were deleted.

      While invoking the API, the above two parameter values (key, tableName) come as a user inputs.

      Drag and drop put items table operation

    7. Then drag and drop the Property mediators into the Design pane as mentioned in the addtable operation. The parameters available for configuring the Property mediator are as follows.

    Add the property mediator to capture the key value. Please follow the steps given in listdetails operation.

    • name : key
    • expression : json-eval($.key)

    • Add the property mediator to capture the tableName values. Please follow the steps given in listdetails operation.

    • name : tableName

    • expression : json-eval($.tableName)

Configure a resource for the listtable operation

  1. Initialize the connector.

You can use the same configuration to initialize the connector. Please follow the steps given in 1.1 for setting up the init operation to the addtable operation.

  1. Set up the listTables operation.

    1. Navigate into the Palette pane and select the graphical operations icons listed under Amazondynamodb Connector section. Then drag and drop the listTables operation into the Design pane.

      Drag and drop list table operation

    2. The listTables operation use to retrieve information about the created tables. listTables operation parameters listed here.

    3. exclusiveStartTableName : The first table name that the listTables operation evaluates. Use the value returned for LastEvaluatedTableName.

    4. limit : The maximum number of table names to retrieve. If this parameter is not specified, the limit is 100.

      While invoking the API, the above two parameter values come as a user inputs.

      Drag and drop list table parameter operation

    5. Then drag and drop the Property mediators into the Design pane as mentioned in addtable operation. The parameters available for configuring the Property mediator are as follows.

    Add the property mediator to capture the exclusiveStartTableName value. Please follow the steps given in the listTables operation.

    • name : exclusiveStartTableName
    • expression : json-eval($.exclusiveStartTableName)

      Add property mediators to capture exclusiveStartTableName

    • Add the property mediator to capture the limit values. Please follow the steps given in the listTables operation.

    • name : limit

    • expression : json-eval($.limit)

      Add property mediators to capture limit

Configure a resource for the deletetable operation

  1. Initialize the connector.

You can use the same configuration to initialize the connector. Please follow the steps given in 1.1 for setting up the init operation to the addtable operation.

  1. Set up the deleteTable operation.

    1. Navigate into the Palette pane and select the graphical operations icons listed under Amazondynamodb Connector section. Then drag and drop the deleteTable operation into the Design pane.

    Drag and drop list table operation

    1. The listTables operation is used to retrieve information about the created tables. The deleteTable operation parameters are listed here.

    2. exclusiveStartTableName : The first table name that the listTables operation evaluates. Use the value returned for LastEvaluatedTableName.

    3. limit : The maximum number of table names to retrieve. If this parameter is not specified, the limit is 100.

      While invoking the API, the above two parameter values come as user inputs.

      Drag and drop list table parameter operation

    4. Then drag and drop the Property mediators into the Design pane as mentioned in addtable operation. The parameters available for configuring the Property mediator are as follows:

    Add the property mediator to capture the tableName value. Please follow the steps given in the deleteTable and listdetails operations.

    • name : tableName
    • expression : json-eval($.tableName)

Get a response.

When you are invoking the created API, the request of the message is going through the each resource. Finally, it is passed to the Respond mediator. The Respond Mediator stops the processing on the current message and sends the message back to the client as a response.

Drag and drop respond mediator to the Design view.

Add Respond mediator

Now you can switch into the Source view and check the XML configuration files of the created API.

amazonDynamoDBAPI.xml
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" context="/resources" name="amazonDynamoDBAPI">
   <resource methods="POST" url-mapping="/addtable">
      <inSequence>
         <property expression="json-eval($.attributeDefinitions)" name="attributeDefinitions" scope="default" type="STRING" />
         <property expression="json-eval($.tableName)" name="tableName" scope="default" type="STRING" />
         <property expression="json-eval($.keySchema)" name="keySchema" scope="default" type="STRING" />
         <property expression="json-eval($.localSecondaryIndexes)" name="localSecondaryIndexes" scope="default" type="STRING" />
         <property expression="json-eval($.provisionedThroughput)" name="provisionedThroughput" scope="default" type="STRING" />
         <amazondynamodb.init>
            <region>us-east-2</region>
            <accessKeyId>AKIAY4QELOL7GF35XBW5</accessKeyId>
            <secretAccessKey>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</secretAccessKey>
            <blocking>false</blocking>
         </amazondynamodb.init>
         <amazondynamodb.createTable>
            <attributeDefinitions>{$ctx:attributeDefinitions}</attributeDefinitions>
            <tableName>{$ctx:tableName}</tableName>
            <keySchema>{$ctx:keySchema}</keySchema>
            <localSecondaryIndexes>{$ctx:localSecondaryIndexes}</localSecondaryIndexes>
            <provisionedThroughput>{$ctx:provisionedThroughput}</provisionedThroughput>
         </amazondynamodb.createTable>
         <respond />
      </inSequence>
      <outSequence>
         <send />
      </outSequence>
      <faultSequence />
   </resource>
   <resource methods="POST" url-mapping="/insertdetails">
      <inSequence>
         <property expression="json-eval($.item)" name="item" scope="default" type="STRING" />
         <property expression="json-eval($.tableName)" name="tableName" scope="default" type="STRING" />
         <amazondynamodb.init>
            <region>us-east-2</region>
            <accessKeyId>AKIAY4QELOL7GF35XBW5</accessKeyId>
            <secretAccessKey>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</secretAccessKey>
            <blocking>false</blocking>
         </amazondynamodb.init>
         <amazondynamodb.putItem>
            <item>{$ctx:item}</item>
            <tableName>{$ctx:tableName}</tableName>
         </amazondynamodb.putItem>
         <respond />
      </inSequence>
      <outSequence>
         <send />
      </outSequence>
      <faultSequence />
   </resource>
   <resource methods="POST" url-mapping="/deletedetails">
      <inSequence>
         <property expression="json-eval($.key)" name="key" scope="default" type="STRING" />
         <property expression="json-eval($.tableName)" name="tableName" scope="default" type="STRING" />
         <amazondynamodb.init>
            <region>us-east-2</region>
            <accessKeyId>AKIAY4QELOL7GF35XBW5</accessKeyId>
            <secretAccessKey>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</secretAccessKey>
            <blocking>false</blocking>
         </amazondynamodb.init>
         <amazondynamodb.deleteItem>
            <key>{$ctx:key}</key>
            <tableName>{$ctx:tableName}</tableName>
            <returnConsumedCapacity>TOTAL</returnConsumedCapacity>
            <returnValues>ALL_OLD</returnValues>
         </amazondynamodb.deleteItem>
         <respond />
      </inSequence>
      <outSequence>
         <send />
      </outSequence>
      <faultSequence />
   </resource>
   <resource methods="POST" url-mapping="/listdetails">
      <inSequence>
         <property expression="json-eval($.key)" name="key" scope="default" type="STRING" />
         <property expression="json-eval($.tableName)" name="tableName" scope="default" type="STRING" />
         <amazondynamodb.init>
            <region>us-east-2</region>
            <accessKeyId>AKIAY4QELOL7GF35XBW5</accessKeyId>
            <secretAccessKey>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</secretAccessKey>
            <blocking>false</blocking>
         </amazondynamodb.init>
         <amazondynamodb.getItem>
            <key>{$ctx:key}</key>
            <tableName>{$ctx:tableName}</tableName>
         </amazondynamodb.getItem>
         <respond />
      </inSequence>
      <outSequence>
         <send />
      </outSequence>
      <faultSequence />
   </resource>
   <resource methods="POST" url-mapping="/listtable">
      <inSequence>
         <property expression="json-eval($.exclusiveStartTableName)" name="exclusiveStartTableName" scope="default" type="STRING" />
         <property expression="json-eval($.limit)" name="limit" scope="default" type="STRING" />
         <amazondynamodb.init>
            <region>us-east-2</region>
            <accessKeyId>AKIAY4QELOL7GF35XBW5</accessKeyId>
            <secretAccessKey>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</secretAccessKey>
            <blocking>false</blocking>
         </amazondynamodb.init>
         <amazondynamodb.listTables>
            <exclusiveStartTableName>{$ctx:exclusiveStartTableName}</exclusiveStartTableName>
            <limit>{$ctx:limit}</limit>
         </amazondynamodb.listTables>
         <respond />
      </inSequence>
      <outSequence>
         <send />
      </outSequence>
      <faultSequence />
   </resource>
   <resource methods="POST" url-mapping="/updatetable">
      <inSequence>
         <property expression="json-eval($.tableName)" name="tableName" scope="default" type="STRING" />
         <property expression="json-eval($.provisionedThroughput)" name="provisionedThroughput" scope="default" type="STRING" />
         <amazondynamodb.init>
            <region>us-east-2</region>
            <accessKeyId>AKIAY4QELOL7GF35XBW5</accessKeyId>
            <secretAccessKey>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</secretAccessKey>
            <blocking>false</blocking>
         </amazondynamodb.init>
         <amazondynamodb.updateTable>
            <tableName>{$ctx:tableName}</tableName>
            <provisionedThroughput>{$ctx:provisionedThroughput}</provisionedThroughput>
         </amazondynamodb.updateTable>
         <respond />
      </inSequence>
      <outSequence>
         <send />
      </outSequence>
      <faultSequence />
   </resource>
   <resource methods="POST" url-mapping="/deletetable">
      <inSequence>
         <property expression="json-eval($.tableName)" name="tableName" scope="default" type="STRING" />
         <amazondynamodb.init>
            <region>us-east-2</region>
            <accessKeyId>AKIAY4QELOL7GF35XBW5</accessKeyId>
            <secretAccessKey>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</secretAccessKey>
            <blocking>false</blocking>
         </amazondynamodb.init>
         <amazondynamodb.deleteTable>
            <tableName>{$ctx:tableName}</tableName>
         </amazondynamodb.deleteTable>
         <respond />
      </inSequence>
      <outSequence>
         <send />
      </outSequence>
      <faultSequence />
   </resource>
</api>

Get the project

You can download the ZIP file and extract the contents to get the project code.

Download ZIP

Deployment

Follow these steps to deploy the exported CApp in the integration runtime.

Deploying on Micro Integrator

You can copy the composite application to the <PRODUCT-HOME>/repository/deployment/server/carbonapps folder and start the server. Micro Integrator will be started and the composite application will be deployed.

You can further refer the application deployed through the CLI tool. See the instructions on managing integrations from the CLI.

Click here for instructions on deploying on WSO2 Enterprise Integrator 6
  1. You can copy the composite application to the <PRODUCT-HOME>/repository/deployment/server/carbonapps folder and start the server.

  2. WSO2 EI server starts and you can login to the Management Console https://localhost:9443/carbon/ URL. Provide login credentials. The default credentials will be admin/admin.

  3. You can see that the API is deployed under the API section.

Testing

Invoke the API as shown below using the curl command. Curl Application can be downloaded from here.

  1. Creating a new table in the Amazon DynamoDB with the specified table name for store employee details.

Sample request

Save a file called data.json with the following payload.

{
   "attributeDefinitions":[
      {
         "AttributeName":"employee_id",
         "AttributeType":"S"
      },
      {
         "AttributeName":"name",
         "AttributeType":"S"
      },
      {
         "AttributeName":"department",
         "AttributeType":"S"
      }
   ],
   "tableName":"Employee_Details",
   "keySchema":[
      {
         "AttributeName":"employee_id",
         "KeyType":"HASH"
      },
      {
         "AttributeName":"name",
         "KeyType":"RANGE"
      }
   ],
   "localSecondaryIndexes":[
      {
         "IndexName":"department",
         "KeySchema":[
            {
               "AttributeName":"employee_id",
               "KeyType":"HASH"
            },
            {
               "AttributeName":"department",
               "KeyType":"RANGE"
            }
         ],
         "Projection":{
            "ProjectionType":"KEYS_ONLY"
         }
      }
   ],
   "provisionedThroughput":{
      "ReadCapacityUnits":5,
      "WriteCapacityUnits":5
   }
} 

Invoke the API as shown below using the curl command.

curl -v POST -d @data.json "http://localhost:8290/resources/addtable" -H "Content-Type:application/json"

Expected Response

{
   "TableDescription":{
      "AttributeDefinitions":[
         {
            "AttributeName":"department",
            "AttributeType":"S"
         },
         {
            "AttributeName":"employee_id",
            "AttributeType":"S"
         },
         {
            "AttributeName":"name",
            "AttributeType":"S"
         }
      ],
      "CreationDateTime":1590068547.564,
      "ItemCount":0,
      "KeySchema":[
         {
            "AttributeName":"employee_id",
            "KeyType":"HASH"
         },
         {
            "AttributeName":"name",
            "KeyType":"RANGE"
         }
      ],
      "LocalSecondaryIndexes":[
         {
            "IndexArn":"arn:aws:dynamodb:us-east-2:610968236798:table/Employee_Details/index/department",
            "IndexName":"department",
            "IndexSizeBytes":0,
            "ItemCount":0,
            "KeySchema":[
               {
                  "AttributeName":"employee_id",
                  "KeyType":"HASH"
               },
               {
                  "AttributeName":"department",
                  "KeyType":"RANGE"
               }
            ],
            "Projection":{
               "ProjectionType":"KEYS_ONLY"
            }
         }
      ],
      "ProvisionedThroughput":{
         "NumberOfDecreasesToday":0,
         "ReadCapacityUnits":5,
         "WriteCapacityUnits":5
      },
      "TableArn":"arn:aws:dynamodb:us-east-2:610968236798:table/Employee_Details",
      "TableId":"10520308-ae1e-4742-b9d4-fc6aae67191e",
      "TableName":"Employee_Details",
      "TableSizeBytes":0,
      "TableStatus":"CREATING"
   }
}
  1. Insert employee details (items) and stored into the specified table.

Sample request

Save a file called data.json with the following payload.

{
   "tableName":"Employee_Details",
   "item":{
      "employee_id":{
         "S":"001"
      },
      "name":{
         "S":"Jhone Fedrick"
      },
      "department":{
         "S":"Engineering"
      }
   }
}

Invoke the API as shown below using the curl command.

curl -v POST -d @data.json "http://localhost:8290/resources/insertdetails" -H "Content-Type:application/json"

Expected Response

{}
3. Update specified table.

Sample request

Save a file called data.json with the following payload.

{
   "tableName":"Employee_Details",
   "provisionedThroughput":{
      "ReadCapacityUnits":12,
      "WriteCapacityUnits":12
   }
}

Invoke the API as shown below using the curl command.

curl -v POST -d @data.json "http://localhost:8290/resources/updatetable" -H "Content-Type:application/json"

Expected Response

{
   "TableDescription":{
      "AttributeDefinitions":[
         {
            "AttributeName":"department",
            "AttributeType":"S"
         },
         {
            "AttributeName":"employee_id",
            "AttributeType":"S"
         },
         {
            "AttributeName":"name",
            "AttributeType":"S"
         }
      ],
      "CreationDateTime":1590068547.564,
      "ItemCount":0,
      "KeySchema":[
         {
            "AttributeName":"employee_id",
            "KeyType":"HASH"
         },
         {
            "AttributeName":"name",
            "KeyType":"RANGE"
         }
      ],
      "LocalSecondaryIndexes":[
         {
            "IndexArn":"arn:aws:dynamodb:us-east-2:610968236798:table/Employee_Details/index/department",
            "IndexName":"department",
            "IndexSizeBytes":0,
            "ItemCount":0,
            "KeySchema":[
               {
                  "AttributeName":"employee_id",
                  "KeyType":"HASH"
               },
               {
                  "AttributeName":"department",
                  "KeyType":"RANGE"
               }
            ],
            "Projection":{
               "ProjectionType":"KEYS_ONLY"
            }
         }
      ],
      "ProvisionedThroughput":{
         "LastIncreaseDateTime":1590071461.81,
         "NumberOfDecreasesToday":0,
         "ReadCapacityUnits":5,
         "WriteCapacityUnits":5
      },
      "TableArn":"arn:aws:dynamodb:us-east-2:610968236798:table/Employee_Details",
      "TableId":"10520308-ae1e-4742-b9d4-fc6aae67191e",
      "TableName":"Employee_Details",
      "TableSizeBytes":0,
      "TableStatus":"UPDATING"
   }
}
  1. Retrieve information about the added employee details (items).

Sample request

Save a file called data.json with the following payload.

{
   "tableName":"Employee_Details",
   "key":{
      "employee_id":{
         "S":"001"
      },
      "name":{
         "S":"Jhone Fedrick"
      }
   }
}

Invoke the API as shown below using the curl command.

curl -v POST -d @data.json "http://localhost:8290/resources/listdetails" -H "Content-Type:application/json"

Expected Response

{
   "Item":{
      "department":{
         "S":"Engineering"
      },
      "name":{
         "S":"Jhone Fedrick"
      },
      "employee_id":{}
   }
}
5. Remove added employee details from the specified table (items).

Sample request

Save a file called data.json with the following payload.

{
   "tableName":"Employee_Details",
   "key":{
      "employee_id":{
         "S":"001"
      },
      "name":{
         "S":"Jhone Fedrick"
      }
   }
}

Invoke the API as shown below using the curl command.

curl -v POST -d @data.json "http://localhost:8290/resources/deletedetails" -H "Content-Type:application/json"

Expected Response

{
   "Attributes":{
      "department":{
         "S":"Engineering"
      },
      "name":{
         "S":"Jhone Fedrick"
      },
      "employee_id":{
         "S":"001"
      }
   },
   "ConsumedCapacity":{
      "CapacityUnits":2,
      "TableName":"Employee_Details"
   }
} 
6. Retrieve information about the created tables.

Sample request

Save a file called data.json with the following payload.

{
   "exclusiveStartTableName":"Employee_Details",
   "limit":4
}

Invoke the API as shown below using the curl command.

curl -v POST -d @data.json "http://localhost:8290/resources/listtable" -H "Content-Type:application/json"

Expected Response

{
   "LastEvaluatedTableName":"TTestMyTablehread",
   "TableNames":[
      "Results",
      "Results1",
      "Results123",
      "TTestMyTablehread"
   ]
} 
7. Remove created table in the Amazon DynamoDB.

Sample request

Save a file called data.json with the following payload.

{
 "tableName":"Employee_Details"
}

Invoke the API as shown below using the curl command.

curl -v POST -d @data.json " http://localhost:8290/resources/deletetable" -H "Content-Type:application/json"

Expected Response

{
   "TableDescription":{
      "ItemCount":0,
      "ProvisionedThroughput":{
         "NumberOfDecreasesToday":0,
         "ReadCapacityUnits":12,
         "WriteCapacityUnits":12
      },
      "TableArn":"arn:aws:dynamodb:us-east-2:610968236798:table/Employee_Details",
      "TableId":"10520308-ae1e-4742-b9d4-fc6aae67191e",
      "TableName":"Employee_Details",
      "TableSizeBytes":0,
      "TableStatus":"DELETING"
   }
}

What's next

Top