Module aws.dynamodb

ballerinax/aws.dynamodb Ballerina library

2.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 months ago

Version: 2.2.0

License: Apache-2.0


Compatibility

Platform: java17

Ballerina version: 2201.8.0-20230830-220400-8a7556d8

GraalVM compatible: Yes


Pull count

Total: 

Current verison: 580


Weekly downloads


Source repository


Keywords

Communication/Email
Cost/Free
Vendor/Google

Contributors

Other versions

See more...