Redshift Connector

A StrataBI Platform Module

Powered by Shaleio

Tier: Supported · module id redshift_connector · type multi_page_app (an app StrataBI renders from its own pages) · requires StrataBI · stands alone

Note
Version 0.1.0, in testing.

Amazon Redshift data for StrataBI tiles. A Lambda runs named, parameterised queries through the Redshift Data API against a Redshift Serverless workgroup or a provisioned cluster and returns the result to the tile. No database drivers, no passwords in the function, no VPC attachment.

text
tile (inputs) → query Lambda → Redshift Data API (ExecuteStatement with parameters) → your workgroup or cluster
                     ↑                                                                  │
                     └────────── DescribeStatement / GetStatementResult ←───────────────┘ → CSV → the tile

Install

  1. Choose the mode (the installer asks):
ModeConnects as
serverlessthe function's IAM role, on a workgroup (workgroup_name)
clusterthe function's IAM role with temporary credentials, on a provisioned cluster (cluster_identifier)
secreta database user kept in AWS Secrets Manager (secret_arn)

Give the target's ARN (target_arn) so the function's rights name exactly that workgroup or cluster.

  1. stratactl install redshift_connector. The output query_role_arn is the function's role.
  2. In Redshift, the function is the database user IAMR:<role name> (IAM modes). Grant it what tiles may read:

``sql GRANT USAGE ON SCHEMA analytics TO "IAMR:stratabi-redshift_connector-query"; GRANT SELECT ON ALL TABLES IN SCHEMA analytics TO "IAMR:stratabi-redshift_connector-query"; ``

  1. Open the module in StrataBI: Connection shows the database user and version; Tables and views lists a schema.

Named queries

Queries live in the module's src/query/queries.json: a name, the SQL, and typed parameters (string, int, float, date, timestamp, identifier) with defaults. A tile names the query (inputs.query, or the tile's id); its inputs fill the parameters, which the Data API binds — values are never pasted into SQL. The Data API passes values as strings, so cast where the type matters:

json
{"name": "daily_counts",
 "sql": "SELECT trunc(event_time) AS day, count(*) AS events FROM analytics.events WHERE event_time > dateadd(day, -CAST(:days AS INTEGER), getdate()) GROUP BY 1 ORDER BY 1",
 "params": {"days": {"type": "int", "default": 30}}}

Use it in a dashboard

json
{"id": "daily_counts", "title": "Events per day", "triggered_by": ["days"],
 "exec": {"type": "lambda", "module_id": "redshift_connector", "lambda_index": 0, "result_kind": "dataframe",
          "result_format": "csv", "result_name": "result.csv", "sync": true, "timeout_seconds": 60},
 "load": {"mode": "input", "keep_previous": true},
 "block": {"type": "plotly", "config": {"figure": {"data": [{"type": "bar", "x": "@day", "y": "@events"}]}}}}

For queries that take longer than a minute, leave out "sync": the tile runs in the background, and the function waits up to its 300-second timeout, then cancels the statement.

Settings

SettingDefaultMeaning
modeserverlessserverless, cluster or secret
databasedevthe database to connect to
allow_adhoc_sqlfalselet tiles send their own read-only SELECT / WITH (inputs.sql)
max_rows50,000rows returned to a tile; more are cut with a note

Security