---
id: connectors/aws-storage-queries
title: AWS object storage and Athena queries with explicit credentials
summary: Compose signed AWS operations, file configuration and application authorization from CLI or server code.
keywords: aws, s3, athena, iam, sts, connectors, storage, queries, cli, files
requires: @jskit-ai/connectors-core, @jskit-ai/connectors-catalog
---

# AWS object storage and Athena queries with explicit credentials

## Use when

An application or an explicitly authorized CLI operator needs objects in one
S3 bucket, or SQL queries in one Athena workgroup. The package provides the
runtime: schema validation, SDK signing and response parsing, fixed regional
origins, file connection storage and operation authorization. AI code only
composes those libraries with the application's identity and resource policy.

## Do not use when

Do not use this as an application login, an AWS account creator, a general SDK
proxy, or proof that a managed host's allocation exists. Do not use a machine's
default AWS credentials for arbitrary application users. Per-user federation,
AWS IAM Identity Center, noncommercial AWS partitions and arbitrary endpoints
are outside the fragment. Athena statements can write data and incur costs;
connecting does not approve arbitrary future SQL.

## Product decisions

Use the exact [S3](https://github.com/mobily-enterprises/jskit-ai/blob/main/packages/connectors-catalog/docs/aws-s3.md) or
[Athena](https://github.com/mobily-enterprises/jskit-ai/blob/main/packages/connectors-catalog/docs/aws-athena.md) JSON. The same file is usable by CLI and a
hosted editor's form. Store the actual secret access key, access key ID and optional
session token outside source. The access key ID uses `settings.accessKeyIdRef`,
the secret uses `authentication.secretRef`, and temporary credentials add
`settings.sessionTokenRef`. A missing explicit binding is an error.

## Invariants

The host resolver must supply a consistent credential set and renew temporary
STS credentials. It must not give a public application the paid account's
identity just because that application names a binding. Resource provisioning,
account assignments, quotas and credential renewal are separate operations.
There is no OAuth callback for these modes. See
[AWS ownership](https://github.com/mobily-enterprises/jskit-ai/blob/main/packages/connectors-catalog/docs/aws-credentials.md).

Each collaborator the composition receives (the connection `service`) is a
required parameter typed in a JSDoc `@param` and called directly, without a
`typeof` probe, a "requires x" guard or a no-op default. Only the production
`fetchImpl = globalThis.fetch` stays as a default. A server feature that uses it
follows
[typed features](https://github.com/mobily-enterprises/jskit-ai/blob/main/packages/agent-docs/site/guide/framework/typed-features.md).

## Framework APIs

Follow the [API-key connection pattern](../api-key-connection/PATTERN.md) to
read configuration, construct encrypted file storage and define authorization.
Register the provider exports needed by that application:

```js
import { awsS3Provider } from "@jskit-ai/connectors-catalog/server/aws-s3";
import { awsAthenaProvider } from "@jskit-ai/connectors-catalog/server/aws-athena";

const providers = [awsS3Provider, awsAthenaProvider];
// Pass providers, validated configuration, store, resolveReference and authorize
// to createConnectionService, or compose the ordinary connector Feature.
```

Call `service.connectApiKey({context, integrationId})` explicitly. S3 checks a
ListObjectsV2 page; Athena checks workgroup metadata. Those reads are useful
verification, not a claim of every object/table permission. API-key
`grantedScopes` is empty; configured S3 read/write selections only limit local
operations. IAM and bucket policies still decide access.

## Example files

[example/integrations.json](example/integrations.json) contains both resource slots.
The [transfer module](example/s3-transfer.js) composes signed GET/PUT with native
Fetch. Optional [format composition](example/formats/data-formats.js) uses ordinary
JSON, CSV and Parquet libraries. Its own package manifest, lockfile and focused
verification command make those optional application dependencies explicit; they
are not installed for every connector consumer. See the S3 guide for composition.
Keep the resource slots in `integrations.json` and these calls in an application-owned server module or CLI command.

For S3, authorize the requested prefix/key against the authenticated user before
invocation. A shared connection does not make the whole bucket public.

```js
const page = await service.invoke({
  context, integrationId: "files", operation: "objects.list",
  input: { prefix: allowedPrefix, maxKeys: 100 }
});
const objects = (page.Contents || []).map((object) => ({
  ...object,
  Key: page.EncodingType === "url" ? decodeURIComponent(object.Key) : object.Key
}));
// NextContinuationToken is opaque: pass it unchanged to the next list call.
// Authorize the selected decoded key through the same policy before signing.
const download = await service.invoke({
  context, integrationId: "files", operation: "objects.downloadUrl",
  input: { key: authorizedKey, expiresInSeconds: 300 }
});
```

`objects.uploadUrl` uses the same key/expiry input and requires configured
`write`. The result's URL is a temporary bearer credential; return it only to the
intended caller, without logging it. Transfer with its exact GET/PUT method and
URL. A PUT body can overwrite that object. Neither signing nor a successful
connection proves delivery. Keys preserve spaces and literal percent signs;
never normalize paths. Standalone `.`/`..` segments are intentionally rejected.
Browser transfers need appropriate bucket CORS for the current app origin.

For Athena discovery, invoke `catalogs.list` (optional `maxResults` 2–50 and
`nextToken`), `databases.list` (`catalog`, optional page fields), then
`tables.list` (`catalog`, `database`, optional page fields). Database/table pages
allow 1–50 rows. Preserve returned column and partition types and pass each
opaque `NextToken` unchanged. Workgroup selection is not catalog isolation:
authorize the catalog/database and exposed metadata for the current caller.
These operations require the Athena/Glue permissions listed in the provider
guide and do not execute SQL or provision a catalog.

For Athena, construct or select the exact authorized statement, database and
catalog on the server. Do not expose an unrestricted `query.start` proxy to
untrusted users. Bind its logical request token and returned query ID to the
application owner in the application's own state (files are sufficient).

```js
const started = await service.invoke({
  context, integrationId: "queries", operation: "query.start",
  input: { sql: authorizedSql, clientRequestToken: logicalRequestToken,
    database: authorizedDatabase }
});
const status = await service.invoke({
  context, integrationId: "queries", operation: "query.status",
  input: { queryId: started.QueryExecutionId }
});
```

The token is 32–128 characters and must identify one authorized logical query.
Reuse it with identical input after an ambiguous start response; the adapter
never replays automatically. A returned query ID is not completion. When status
is SUCCEEDED, request `query.results` with that authorized ID and a bounded page
size. Preserve column types, header rows, empty cells and string values. Pass
`NextToken` unchanged to retrieve another page.

For cancellation, call `query.cancel` with an authorized query ID; then inspect
status when final cancellation must be known. Aborting a local HTTP request,
closing the UI or disconnecting does not cancel an AWS query. Before status,
results or cancellation, the library checks the execution's workgroup. The
application must still enforce ownership within that workgroup.

## Variation points

Choose long-lived IAM-user bindings or host-renewed STS bindings. Add S3 write
only when the application supports uploads. Result storage can be supplied by
the Athena workgroup or configured in the file; the workgroup can enforce its
own location. These choices use the same runtime APIs.

## Avoid

Do not expose presigned URLs in logs, infer table permission from a workgroup
read, treat workgroup membership as user isolation, or poll queries without an
application-controlled limit.

Do not probe a collaborator, default one to `null`, `{}` or a no-op, fill a slot
with a setter after construction, or keep a module-level registry.

## Verification

Missing credential references fail before HTTP. Expired/rejected AWS credentials
require renewal and reconnection. Region changes require verification again.
Permission failures and account throttling are distinct, redacted errors.
Signing and SDK requests respect the core timeout/cancellation signal and use
one attempt with no redirects. Never respond to an IAM denial by switching to
another account or broadening a policy automatically.

Use the focused `packages/connectors-catalog/test/aws.test.js` for protocol and
file-persistence proof. Public editor tests cover portable fields and reload;
shared-form checks cover responsive composition. No live AWS account, actual
object transfer, SQL execution or generated app is needed for this test scope.
