ballerinax/aws.redshiftdata Ballerina library

1.1.0

Overview

Amazon Redshift is a powerful and fully-managed data warehouse service provided by Amazon Web Services (AWS), designed to efficiently analyze large datasets with high performance and scalability.

The ballerinax/aws.redshiftdata package allows developers to interact with Amazon Redshift Data API seamlessly using Ballerina. The Redshift Data API simplifies data access by eliminating the need for managing persistent database connections or the Redshift JDBC driver.

Setup guide

Login to AWS Console

Log into the AWS Management Console. If you don’t have an AWS account yet, you can create one by visiting the AWS sign-up page. Sign up is free, and you can explore many services under the Free Tier.

Create a user

  1. In the AWS Management Console, search for IAM in the services search bar.

  2. Click on IAM

    create-user-1.png

  3. Click Users

    create-user-2.png

  4. Click Create User

    create-user-3.png

  5. Provide a suitable name for the user and continue

    specify-user-details.png

  6. Add necessary permissions by adding the user to a user group, copy permissions or directly attach the policies. And click next.

    set-user-permissions.png

  7. Review and create the user

    review-create-user.png

Get user access keys

  1. Click the user that created

    users.png

  2. Click Create access key

    create-access-key-1.png

  3. Click your use case and click next.

    select-usecase.png

  4. Record the Access Key and Secret access key. These credentials will be used to authenticate your Ballerina application with the Redshift cluster.

    retrieve-access-key.png

Setup a Cluster

To use the Ballerina AWS Redshift data connector, follow these steps to set up an Amazon Redshift cluster:

Step 1: Navigate to Amazon Redshift and create a cluster

  1. In the AWS Management Console, search for Redshift in the services search bar.

  2. Click on Amazon Redshift.

    create-cluster-1.png

  3. Click on the Create cluster button to initiate the process of creating a new Amazon Redshift cluster.

    create-cluster-2.png

Step 2: Configure cluster settings

  1. Configure your Redshift cluster settings, including cluster identifier, database name, credentials, and other relevant parameters.

    configure-cluster-1.png

  2. Configure security groups to control inbound and outbound traffic to your Redshift cluster. Ensure that your Ballerina application will have the necessary permissions to access the cluster.

    configure-security-groups.png

  3. Record the username during the cluster configuration. This will be used to authenticate your Ballerina application with the Redshift cluster.

    database-configurations.png

  4. Finally, review your configuration settings, and once satisfied, click Create cluster to launch your Amazon Redshift cluster.

Step 3: Wait for cluster availability

  1. It may take some time for your Redshift cluster to be available. Monitor the cluster status in the AWS Console until it shows as "Available".

    wait-for-availability.png

Note: Amazon Redshift now offers a serverless option, allowing you to use the data warehouse without managing infrastructure. Redshift Serverless automatically scales to handle your workloads, providing a flexible and efficient way to run analytics. To configure a Redshift serverless setup, please refer to AWS documentation.

Quickstart

To use the aws.redshiftdata connector in your Ballerina project, modify the .bal file as follows:

Step 1: Import the module

Copy
import ballerinax/aws.redshiftdata;

Step 2: Instantiate a new connector

Create a new redshiftdata:Client by providing the region, authentication configurations and dbAccessConfig.

The dbAccessConfig in the ConnectionConfig record defines the database access configuration for connecting to the Redshift Data API. It can be set to either a Cluster or a WorkGroup (Serverless mode). Additionally, users can override this configuration for specific requests by providing it in individual calls to methods like execute or batchExecute, allowing for more granular control over database access per execution.

Copy
configurable string accessKeyId = ?;
configurable string secretAccessKey = ?;
configurable redshiftdata:Cluster dbAccessConfig = ?;

redshiftdata:Client redshiftdata = check new ({
   region: redshiftdata:US_EAST_2,
   auth: {
      accessKeyId,
      secretAccessKey
   },
   dbAccessConfig
});

Step 3: Invoke the connector operations

Now, utilize the available connector operations.

Copy
redshiftdata:ExecutionResponse response = check redshiftdata->execute(`SELECT * FROM Users`);

redshiftdata:DescriptionResponse descriptionResponse = check redshiftdata->describe(response.statementId);

stream<User, redshiftdata:Error?> statementResult = check redshiftdata->getResultAsStream(response.statementId);

Step 4: Run the Ballerina application

Use the following command to compile and run the Ballerina program.

Copy
bal run

Examples

The aws.redshiftdata connector provides practical examples illustrating usage in various scenarios. Explore these examples.

  1. Manage users - This example demonstrates how to use the Ballerina Redshift Data connector to perform SQL operations on an AWS Redshift cluster. It includes creating a table, inserting data, and querying data.

  2. Music store - This example illustrates the process of creating an HTTP RESTful API with Ballerina to perform basic CRUD operations on a database, specifically AWS Redshift, involving setup, configuration, and running examples.

Import

import ballerinax/aws.redshiftdata;Copy

Metadata

Released date: 26 days ago

Version: 1.1.0

License: Apache-2.0


Compatibility

Platform: java21

Ballerina version: 2201.11.0

GraalVM compatible: Yes


Pull count

Total: 1

Current verison: 1


Weekly downloads


Source repository


Keywords

Data Warehouse

Columnar Storage

Cost/Paid

vendor/aws


Contributors

Other versions