---
id: connectors/redshift-queries
title: Redshift queries with shared AWS credentials
summary: Compose file configuration, Redshift Data API operations and application query ownership.
keywords: redshift, aws, sql, warehouse, serverless, provisioned, iam, connectors, cli, files
requires: @jskit-ai/connectors-core, @jskit-ai/connectors-catalog
---

# Redshift queries with shared AWS credentials

## Use when

A CLI operator or application backend needs database/schema/table metadata or authorized SQL in
one configured Redshift warehouse. JSKIT owns configuration validation, AWS SDK
signing, operation input validation, target checks and response parsing. The
application owns which user may submit a query or access its result.

## Do not use when

This fragment does not provide application login, per-user IAM Identity Center
federation, warehouse provisioning or a managed paid/public allocation. Never
turn a shared AWS key into an unrestricted SQL endpoint for application users.
SQL can modify data; read-only behavior requires appropriate database grants.

## Product decisions

Select serverless or provisioned in the same JSON the editor edits. Serverless
requires a workgroup name; provisioned requires a cluster identifier and may use
an explicit database user. Both require a database and region. Store AWS secrets
outside the file. Temporary credentials additionally need `sessionTokenRef` and
host renewal. See the [Redshift guide](https://github.com/mobily-enterprises/jskit-ai/blob/main/packages/connectors-catalog/docs/amazon-redshift.md) for setup,
field names, automation feasibility and remaining federation work.

## Invariants

Use the application's existing authentication and authorization policy to build
the trusted context. Bind logical query tokens and returned statement IDs to
the actual application/user in application-owned state; a text file can hold
that state. Authorize exact SQL, parameter values and statement ownership before
invoking the service. Matching the configured warehouse is only a target check.

The library does not resolve ambient AWS profiles or switch to a more privileged
account after a denial. The application resolves its own credential bindings; editable references do
not grant AWS permissions. This shared credential mode has no provider callback
URL and does not depend on a hosting platform's registration or allocation.

## Framework APIs

Follow the [API-key connection pattern](../api-key-connection/PATTERN.md) to read
configuration, create protected file connection storage, resolve explicit
bindings and implement `authorize`. Register this runtime export:

```js
import { amazonRedshiftProvider } from "@jskit-ai/connectors-catalog/server/amazon-redshift";
const providers = [amazonRedshiftProvider];
// Pass providers with configuration, store, resolveReference and authorize
// to createConnectionService or the ordinary connector Feature.
```

The library's `connectApiKey({context, integrationId})` reads a table metadata
page. It does not submit SQL or grant future query permission. Use
`databases.list` for visible database names, `schemas.list` for schemas in the
configured database, `tables.list` for tables and `table.describe` for columns.
Each listing accepts `maxResults` (1–1000) and an opaque `nextToken`; schema
listing also accepts `schemaPattern`. An absent or empty NextToken ends paging.
Database names returned by discovery do not change this connection's configured
target or authorize another database. Use another project-owned configuration
slot for another database and authorize metadata visibility before invocation.

## Example files

[example/integrations.json](example/integrations.json) has two independent
configuration slots demonstrating both deployment types. Actual resource names
and environment bindings must come from the owner. Do not generate a new app to
use these libraries; compose them in the existing backend or CLI entry point.

After the application has authorized the statement and stored its logical
request token, call:

```js
const submitted = await service.invoke({
  context, integrationId: "serverless-reports", operation: "query.start",
  input: {
    sql: "select order_id::varchar, total from reporting.orders where customer_id = :customer limit 100",
    parameters: [{ name: "customer", value: authorizedCustomerId }],
    clientToken: storedLogicalRequestToken
  }
});
// Persist submitted.Id with the authorized application's query owner.
const status = await service.invoke({
  context, integrationId: "serverless-reports", operation: "query.status",
  input: { statementId: submitted.Id }
});
```

Use parameters for values; do not concatenate user input into the SQL. Tokens
are required, case-sensitive and 1–64 characters. Reuse the same token only for
the same logical request and identical input within AWS's deduplication window.
An ambiguous response must not trigger an automatic submission with a new token.

A returned ID is submission, not completion. `query.status` reports SUBMITTED,
PICKED, STARTED, FINISHED, ABORTED or FAILED. The application controls bounded
polling and cancellation. When status is FINISHED with a result set:

```js
const page = await service.invoke({
  context, integrationId: "serverless-reports", operation: "query.results",
  input: { statementId: authorizedStatementId }
});
// ColumnMetadata describes each position in Records. Preserve typed cells.
// If another page is needed, pass page.NextToken unchanged as nextToken.
```

Result cells retain AWS's tags: `stringValue`, `longValue`, `doubleValue`,
`booleanValue`, `isNull` and `blobValue`. Do not collapse empty strings, zero or
false into null. Binary values are Uint8Array; explicitly encode them in an
application JSON response. Large integers outside JavaScript's safe range are
rejected: select them as VARCHAR for exact text. Results are one AWS page;
there is no `maxResults` parameter for `query.results`.

For explicit remote cancellation, authorize the statement owner then invoke
`query.cancel` with its ID. The returned boolean receipt does not establish
rollback or a final job state. Read status if the final outcome is needed.
Closing a UI, aborting local HTTP or disconnecting does not cancel remote SQL.

## Variation points

Change only the configured resource slot when targeting a provisioned cluster.
The operation interface stays the same. An explicit `databaseUser` uses that
database identity; omit it for the IAM-derived identity. Table listing and
description accept a bounded page size and opaque cursors. Metadata filters
support AWS's SQL-style patterns.

## Avoid

Do not expose arbitrary database/workgroup overrides, use query IDs as bearer
authorization, log SQL/result metadata indiscriminately, assume that a table
listing proves every SELECT permission, or reimplement AWS signing in scaffolding.
The runtime does not enforce SELECT-only SQL by parsing or matching prefixes.

## Verification

Run the single focused `test/amazon-redshift.test.js` file in the catalogue
package. It uses real SDK signing with controlled responses and file storage.
It covers both targets, input validation, SQL parameters, statement checks,
typed result pages, credentials, errors and local cancellation. Shared-form
browser checks pass at phone, tablet and desktop sizes; Public editor checks
pass at phone/desktop sizes for both deployment types, region selection,
validation, inactive-field removal and save/reload.
No live AWS account, executed SQL or generated application is claimed.
