Zum Hauptinhalt springen

How to authenticate StackQL to AWS

StackQL authenticates to AWS using the standard AWS credential environment variables. Set them before starting a StackQL shell, exec command, server, or MCP server; no configuration file is required.

Steps​

  1. Create or identify an IAM principal (user or role) with the permissions your queries need. For read-only querying, the ReadOnlyAccess managed policy or a narrower equivalent is sufficient.

  2. Export the credentials as environment variables:

export AWS_ACCESS_KEY_ID=YOURACCESSKEYID
export AWS_SECRET_ACCESS_KEY=YOURSECRETACCESSKEY

For temporary credentials (an assumed role via sts assume-role, or an AWS CloudShell session, which sets these automatically), the session token is exported as well:

export AWS_SESSION_TOKEN=YOURSESSIONTOKEN
  1. Pull the AWS provider (first use only):
REGISTRY PULL aws;
  1. Verify with a query:
SELECT instance_id, instance_type
FROM aws.ec2.instances
WHERE region = 'us-east-1';

A successful result set confirms authentication. Note that AWS queries require a region predicate in the WHERE clause - this is a routing parameter, not a credential setting.

Assume a role​

From StackQL v1.1.959, StackQL can assume an IAM role itself. Set the provider's auth type to aws_assume_role in the --auth configuration and name the role; StackQL calls STS AssumeRole with the base credentials and signs every provider request with the temporary credentials it receives:

stackql shell --auth='{"aws": {"type": "aws_assume_role", "keyIDenvvar": "AWS_ACCESS_KEY_ID", "credentialsenvvar": "AWS_SECRET_ACCESS_KEY", "aws_role_arn": "arn:aws:iam::123456789012:role/StackQLReadOnly"}}'
KeyDescription
aws_role_arn or aws_role_arn_env_varRequired. The role ARN, or the name of an environment variable holding it; a literal ARN wins when both are set.
aws_role_external_id or aws_role_external_id_env_varOptional external ID sent with the request.
aws_role_session_nameRole session name, 2 to 64 characters. Default stackql-assume-role-session.
aws_role_duration_secondsOptional session duration, 900 to 43200 seconds. STS's default applies when omitted.
aws_sts_regionRegion of the STS endpoint, independent of the query's region. Default us-east-1.
aws_sts_endpointOptional STS endpoint URL. Default https://sts.<aws_sts_region>.amazonaws.com (.amazonaws.com.cn for China regions).

The base credentials that sign the STS call come from keyIDenvvar (or keyID) and credentialsenvvar, otherwise from AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN, otherwise from the shared credentials and config profile named by profile or AWS_PROFILE. Role chaining (assuming a role from an assumed role configured the same way) is not supported.

  • One STS call serves every statement in a session, including all branches of a UNION, and the credentials are refreshed shortly before they expire.
  • An STS failure stops the statement before any provider request is sent, with a message such as STS AssumeRole rejected: status 403, code AccessDenied.
  • SET "$.auth.aws" = '...' switches the role for later queries in the session; see Provider Sessions and Secrets.

Where the variables apply​

The same environment variables work in every StackQL execution mode:

  • Interactive shell: stackql shell
  • Batch: stackql exec "..."
  • Server mode: stackql srv (PostgreSQL wire protocol)
  • MCP server: stackql mcp, or via the env block of an MCP client configuration such as claude_desktop_config.json

In CI systems, source the variables from the platform's secret store rather than hardcoding them. Metadata operations (SHOW, DESCRIBE, REGISTRY) work without credentials; only data operations (SELECT, INSERT, UPDATE, DELETE, EXEC) require an authenticated session.