Module aws.dynamodb

ballerinax/aws.dynamodb Ballerina library

1.2.0

Overview

The Ballerina AWS DynamoDB connector provides the capability to programatically handle AWS DynamoDB related operations.

This module supports Amazon DynamoDB REST API 20120810.

Prerequisites

Before using this connector in your Ballerina application, complete the following:

  1. Create an AWS account
  2. Obtain tokens

Quickstart

To use the AWS DynamoDB connector in your Ballerina application, update the .bal file as follows:

Step 1: Import connector

Import the ballerinax/aws.dynamodb module into the Ballerina project.

Copy
import ballerinax/aws.dynamodb;

Step 2: Create a new connector instance

Create an dynamodb:ConnectionConfig with the tokens obtained, and initialize the connector with it.

Copy
dynamodb:ConnectionConfig amazonDynamodbConfig = {
    awsCredentials: {
        accessKeyId: "<ACCESS_KEY_ID>",
        secretAccessKey: "<SECRET_ACCESS_KEY>"

    },
    region: "<REGION>"
};

dynamodb:Client amazonDynamoDBClient = check new(amazonDynamodbConfig);

Step 3: Invoke connector operation

  1. Now you can use the operations available within the connector. Note that they are in the form of remote operations.
    Following is an example on how to create table in DynamoDB using the connector.

    Copy
    ublic function main() returns error? {
       dynamodb:TableCreateRequest payload = {
           AttributeDefinitions: [
                   {
                       AttributeName: "ForumName",
                       AttributeType: "S"
                   },
                   {
                       AttributeName: "Subject",
                       AttributeType: "S"
                   },
                   {
                       AttributeName: "LastPostDateTime",
                       AttributeType: "S"
                   }
               ],
               TableName: mainTable,
               KeySchema: [
                   {
                       AttributeName: "ForumName",
                       KeyType: HASH
                   },
                   {
                       AttributeName: "Subject",
                       KeyType: RANGE
                   }
               ],
               LocalSecondaryIndexes: [
                   {
                       IndexName: "LastPostIndex",
                       KeySchema: [
                           {
                               AttributeName: "ForumName",
                               KeyType: HASH
                           },
                           {
                               AttributeName: "LastPostDateTime",
                               KeyType: RANGE
                           }
                       ],
                       Projection: {
                           ProjectionType: KEYS_ONLY
                       }
                   }
               ],
               ProvisionedThroughput: {
                   ReadCapacityUnits: 5,
                   WriteCapacityUnits: 5
               },
               Tags: [
                   {
                       Key: "Owner",
                       Value: "BlueTeam"
                   }
               ]
           };
       dynamodb:TableCreateResponse createTablesResult = check dynamoDBClient->createTable(payload);
  2. Use bal run command to compile and run the Ballerina program.

Import

import ballerinax/aws.dynamodb;Copy

Metadata

Released date: about 2 years ago

Version: 1.2.0

License: Apache-2.0


Compatibility

Platform: java11

Ballerina version: 2201.0.0


Pull count

Total: 1007

Current verison: 6


Weekly downloads


Source repository


Keywords

IT Operations/Databases

Cost/Freemium

Vendor/Amazon


Contributors

Other versions

See more...