Data Connectors

DynamoDB Data Connector

Query Amazon DynamoDB tables with SQL, unnest nested attributes, and keep accelerated copies current with DynamoDB Streams.

Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability. This connector enables using DynamoDB tables as data sources for federated SQL queries in Spice.

datasets:
  - from: dynamodb:users
    name: users
    params:
      dynamodb_aws_region: us-west-2
      dynamodb_aws_access_key_id: ${secrets:aws_access_key_id} # Optional
      dynamodb_aws_secret_access_key: ${secrets:aws_secret_access_key} # Optional
      dynamodb_aws_session_token: ${secrets:aws_session_token} # Optional

Configuration

from

The from field should specify the DynamoDB table name:

fromDescription
dynamodb:tableRead data from a DynamoDB table named table

name

The dataset name. This will be used as the table name within Spice.

Example:

datasets:
  - from: dynamodb:users
    name: my_users
    params: ...
SELECT COUNT(*) FROM my_users;

The dataset name cannot be a reserved keyword.

params

The DynamoDB data connector supports the following configuration parameters:

Parameter NameDescription
dynamodb_aws_regionRequired. The AWS region containing the DynamoDB table
dynamodb_aws_access_key_idOptional. AWS access key ID for authentication. If not provided, credentials will be loaded from environment variables or IAM roles
dynamodb_aws_secret_access_keyOptional. AWS secret access key for authentication. If not provided, credentials will be loaded from environment variables or IAM roles
dynamodb_aws_session_tokenOptional. AWS session token for authentication
dynamodb_aws_authOptional. Authentication method. Use iam_role (default) for IAM role-based authentication or key for explicit access key credentials.
dynamodb_aws_iam_role_sourceOptional. IAM role credential source (only used when dynamodb_aws_auth: iam_role). auto (default) uses the default AWS credential chain, metadata uses only instance/container metadata (IMDS, ECS, EKS/IRSA), env uses only environment variables
unnest_depthOptional. Maximum nesting depth for unnesting embedded documents into a flattened structure. Higher values expand deeper nested fields.
schema_infer_max_recordsOptional. The number of documents to use to infer the schema. Defaults to 10
scan_segmentsOptional. Number of segments for Scan request. 'auto' by default, which will calculate number of segments based on number of the records in a table
scan_intervalOptional. Interval between polling for new records in a DynamoDB stream. Default: 0s. See Streams.
dynamodb_replication_ready_lagOptional. For refresh_mode: changes, the dataset is marked Ready once its replication lag (now minus the newest applied source-commit time) falls below this. It stays not-ready while snapshotting or draining a backlog, so it never serves stale data. Default: 2s. See Streams.
dynamodb_replication_initial_snapshotOptional. When refresh_mode: changes first loads the table's existing items: auto (default) scans when no resumable stream checkpoint exists and resumes without a scan when one does; disabled streams changes only, from the current stream tip; always scans on every start, discarding any persisted checkpoint. Default: auto.
dynamodb_replication_invalid_checkpoint_behaviorOptional. Behavior when the persisted stream checkpoint can no longer be honored (past the ~24h shard retention). One of error (default: marks dataset as Error) or restart (re-bootstraps from a fresh scan). Default: error.
endpoint_urlOptional. Custom endpoint URL for DynamoDB-compatible services (e.g., DynamoDB Local, ScyllaDB Alternator).
ready_lagDeprecated. Renamed to dynamodb_replication_ready_lag; still accepted as an alias.
lag_exceeds_shard_retention_behaviorDeprecated. Renamed to dynamodb_replication_invalid_checkpoint_behavior (error | restart). ready_after_load maps to restart; ready_before_load has been removed and also maps to restart.
time_formatOptional. Go-style time format used for parsing/formatting timestamps. See Time Format
write_parallelismOptional. Number of parallel operations for writing and deleting data to DynamoDB. Default: 10

Authentication

The DynamoDB connector supports two authentication methods controlled by the dynamodb_aws_auth parameter:

datasets:
  - from: dynamodb:my_table
    params:
      dynamodb_aws_auth: iam_role | key                   # iam_role is default
      dynamodb_aws_iam_role_source: auto | metadata | env # auto is default (only used with iam_role)

IAM Role Authentication (dynamodb_aws_auth: iam_role)

This is the default authentication method. When using IAM role authentication, the dynamodb_aws_iam_role_source parameter controls which credential sources are used:

Source ValueDescriptionCredential Sources
auto (default)Uses the default AWS credential chainAll sources listed below, in order
metadataUses only instance/container metadataWeb Identity Token, ECS Container Credentials, EC2 Instance Metadata (IMDSv2)
envUses only environment variablesAWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN

Key-Based Authentication (dynamodb_aws_auth: key)

When dynamodb_aws_auth is set to key, credentials must be provided explicitly:

datasets:
  - from: dynamodb:my_table
    params:
      dynamodb_aws_auth: key
      dynamodb_aws_access_key_id: ${secrets:aws_access_key_id}
      dynamodb_aws_secret_access_key: ${secrets:aws_secret_access_key}
      dynamodb_aws_session_token: ${secrets:aws_session_token}  # Optional, for temporary credentials

Default Credential Chain (auto)

When using dynamodb_aws_auth: iam_role with dynamodb_aws_iam_role_source: auto (or when both parameters are omitted), credentials are loaded from the following sources in order:

  1. Environment Variables:

    • AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
    • AWS_SESSION_TOKEN (if using temporary credentials)
  2. Shared AWS Config/Credentials Files:

    • Config file: ~/.aws/config (Linux/Mac) or %UserProfile%\.aws\config (Windows)

    • Credentials file: ~/.aws/credentials (Linux/Mac) or %UserProfile%\.aws\credentials (Windows)

    • The AWS_PROFILE environment variable can be used to specify a named profile, otherwise the [default] profile is used.

    • Supports both static credentials and SSO sessions

    • Example credentials file:

      # Static credentials
      [default]
      aws_access_key_id = YOUR_ACCESS_KEY
      aws_secret_access_key = YOUR_SECRET_KEY
      
      # SSO profile
      [profile sso-profile]
      sso_start_url = https://my-sso-portal.awsapps.com/start
      sso_region = us-west-2
      sso_account_id = 123456789012
      sso_role_name = MyRole
      region = us-west-2
  3. AWS STS Web Identity Token Credentials:

    • Used primarily with OpenID Connect (OIDC) and OAuth
    • Common in Kubernetes environments using IAM roles for service accounts (IRSA)
  4. ECS Container Credentials:

    • Used when running in Amazon ECS containers
    • Automatically uses the task's IAM role
    • Retrieved from the ECS credential provider endpoint
    • Relies on the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI or AWS_CONTAINER_CREDENTIALS_FULL_URI which are automatically injected by ECS.
  5. AWS EC2 Instance Metadata Service (IMDSv2):

    • Used when running on EC2 instances.
    • Automatically uses the instance's IAM role.
    • Retrieved securely using IMDSv2.

The connector will try each source in order until valid credentials are found. If no valid credentials are found, an authentication error will be returned.

Required IAM Permissions

The IAM role or user needs the following permissions to access DynamoDB tables:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:Scan",
                "dynamodb:Query",
                "dynamodb:DescribeTable"
            ],
            "Resource": [
                "arn:aws:dynamodb:*:*:table/YOUR_TABLE_NAME"
            ]
        }
    ]
}

Permission Details

PermissionPurpose
dynamodb:ScanRequired. Allows reading all items from the table
dynamodb:QueryRequired. Allows reading items from the table using partition key
dynamodb:DescribeTableRequired. Allows fetching table metadata and schema information
dynamodb:BatchWriteItemRequired for INSERT and DELETE. Both write paths issue BatchWriteItem requests
dynamodb:UpdateItemRequired for UPDATE. Allows modifying existing items in the table

Example IAM Policies

Minimal Policy (Read-only access to specific table)

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:Scan",
                "dynamodb:Query",
                "dynamodb:DescribeTable"
            ],
            "Resource": "arn:aws:dynamodb:us-west-2:123456789012:table/users"
        }
    ]
}

Access to Multiple Tables

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:Scan",
                "dynamodb:Query",
                "dynamodb:DescribeTable"
            ],
            "Resource": [
                "arn:aws:dynamodb:us-west-2:123456789012:table/users",
                "arn:aws:dynamodb:us-west-2:123456789012:table/orders"
            ]
        }
    ]
}

Access to All Tables in a Region

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:Scan",
                "dynamodb:Query",
                "dynamodb:DescribeTable"
            ],
            "Resource": "arn:aws:dynamodb:us-west-2:123456789012:table/*"
        }
    ]
}

Data Types

The table below shows the DynamoDB data types supported, along with the type mapping to Apache Arrow types in Spice.

DynamoDB TypeDescriptionArrow TypeNotes
BoolBooleanBoolean
SStringUtf8
SStringTimestamp(Millisecond)Naive timestamp if it matches time_format without timezone
SStringTimestamp(Millisecond, <timezone>)Timezone-aware timestamp if it matches time_format with timezone
SStringDate32Date-only string in YYYY-MM-DD format (when it does not match time_format)
SsString SetList<Utf8>
NNumberInt64 | Float64
NsNumber SetList<Int64|Float64>
BBinaryBinary
BsBinary SetList<Binary>
LListList<Utf8>DynamoDB arrays can be heterogeneous e.g. [1, "foo", true], Arrow arrays must be homogeneous - use strings to preserve all data
MMapUtf8 or UnflattenedDepending on unnest_depth value

Time format

Since DynamoDB stores timestamps as strings, Spice supports parsing timestamps using a customizable format. By default, Spice will try to parse timestamps using ISO8601 format, but you can provide a custom format using the time_format parameter.

Once Spice is able to parse a timestamp, it will convert it to a Timestamp(Millisecond) Arrow type, and will use the same format to serialize it back to DynamoDB for filter pushdown.

This parameter uses Go-style time formatting, which uses a reference time of Mon Jan 2 15:04:05 MST 2006.

Format PatternExample ValueDescription
2006-01-02T15:04:05.000Z07:002024-03-15T14:30:00.000ZISO8601 / RFC3339 with milliseconds and timezone (default)
2006-01-02T15:04:05.999Z07:002024-03-15T14:30:00.123-07:00ISO8601 with milliseconds and timezone
2006-01-02T15:04:052024-03-15T14:30:00ISO8601 without timezone (naive timestamp)
2006-01-02 15:04:052024-03-15 14:30:00Date and time with space separator
01/02/2006 15:04:0503/15/2024 14:30:00US-style date with time
02/01/2006 15:04:0515/03/2024 14:30:00European-style date with time
Jan 2, 2006 3:04:05 PMMar 15, 2024 2:30:00 PMHuman-readable with 12-hour clock
2006010215040520240315143000Compact format (no separators)

Go's format uses specific reference values that must appear exactly as shown:

ComponentReference ValueAlternatives
Year200606 (2-digit)
Month011, Jan, January
Day022
Hour (24h)15-
Hour (12h)033
Minute044
Second055
AM/PMPMpm
TimezoneZ07:00-0700, MST
Milliseconds.000.999 (trailing zeros trimmed)
Microseconds.000000.999999 (trailing zeros trimmed)
Nanoseconds.000000000.999999999 (trailing zeros trimmed)

Unnesting

Consider the following document:

{
  "a": 1,
  "b": {
    "x": 2,
    "y": {
      "z": 3
    }
  }
}

Using unnest_depth you can control the unnesting behavior. Here are the examples:

unnest_depth: 0

sql> select * from test_table;
+-----------+---------------------+
| a (Int32) | b (Utf8)            |
+-----------+---------------------+
| 1         | {"x":2,"y":{"z":3}} |
+---+-----------------------------+

unnest_depth: 1

sql> select * from test_table;
+-----------+-------------+------------+
| a (Int32) | b.x (Int32) | b.y (Utf8) |
+-----------+-------------+------------+
| 1         | 2           | {"z":3}    | 
+-----------+-------------+------------+

unnest_depth: 2

sql> select * from test_table;
+-----------+-------------+---------------+
| a (Int32) | b.x (Int32) | b.y.z (Int32) |
+-----------+-------------+---------------+
| 1         | 2           | 3             |
+-----------+-------------+---------------+

JSON Nesting

When working with DynamoDB tables that have many columns, you can consolidate unspecified columns into a single JSON column using the json_object metadata option. This is useful when you only need a few columns as discrete fields and want to bundle the remaining columns into a single JSON structure.

Configuration

To use JSON nesting, define your desired columns explicitly in the columns list and add a "catch-all" column with json_object: "*" metadata. Any columns from the source table that are not explicitly listed will be nested into this JSON column.

datasets:
  - from: dynamodb:my_table
    name: my_table
    params:
      dynamodb_aws_region: us-west-2
    columns:
      - name: PK
      - name: SK
      - name: Baz
      - name: data_json
        metadata:
          json_object: "*"

Example

Given a DynamoDB table with this schema:

ColumnType
PKString
SKString
FooMap
BarList
BazString

The configuration above produces:

ColumnType
PKString
SKString
BazString
data_jsonJSON ({"Foo": <map>, "Bar": <list>})

The Foo and Bar columns, which were not explicitly listed, are automatically nested into the data_json column as a JSON object.

Interaction with unnest_depth

When both unnest_depth and json_object are specified, the operations are applied in this order:

  1. Unnesting first: Nested structures are flattened according to the unnest_depth value
  2. JSON nesting second: Unspecified columns are then consolidated into the json_object column

Consider this DynamoDB dataset:

+----+------+-------------------+------------------------------------------------------+
| PK | SK   | Baz               | Foo                                                  | 
+----+------+-------------------+------------------------------------------------------+
| 1  | 200  | some_string_value | { "Age" : { "N" : "35" }, "Name" : { "S" : "Joe" } } |
+----+------+-------------------+------------------------------------------------------+

And this configuration

datasets:
  - from: dynamodb:my_table
    name: my_table
    params:
      dynamodb_aws_region: us-west-2
      unnest_depth: 1
    columns:
      - name: PK
      - name: SK
        metadata:
          json_object: "*"

Will produce the following Spice dataset:

+----+-----+---------------------------------------------------------+
| PK | SK  | json_data                                               |
+----+-----+---------------------------------------------------------+
| 1  | 200 | {"Baz":"some_string", "Foo.Age":35.0, "Foo.Name":"Joe"} |
+----+-----+---------------------------------------------------------+

Query Pushdown

Spice sends the selected columns and the supported WHERE conditions to DynamoDB. An equality on the partition key turns the read into a DynamoDB Query instead of a Scan, and conditions on the sort key in the same query become part of its key condition expression. Other supported conditions become a filter expression.

DynamoDB evaluates NOT, <>, and NOT IN with two-valued logic, so they match an item that does not have the attribute or holds NULL in it, while SQL excludes that item. Spice sends these conditions to narrow the read and evaluates them again on the items DynamoDB returns, so the result matches SQL. For example, WHERE v <> 30 does not return an item without a v attribute.

Run EXPLAIN to see the request: the DynamoDBTableProviderExec node shows a Query or Scan request plan with its key condition, filter, and projection expressions.

Data Manipulation (DML)

The DynamoDB connector supports INSERT, UPDATE, and DELETE operations.

-- Insert a new item
INSERT INTO users (id, email, name) VALUES (42, 'user@example.com', 'Jane');

-- Update existing items
UPDATE users SET name = 'Jane Doe' WHERE id = 42;

-- Delete items
DELETE FROM users WHERE id = 42;

Write operations use the table's primary key (partition key and optional sort key) to identify items. The write_parallelism parameter controls how many DynamoDB API calls are issued concurrently for batch operations (default: 10).

Examples

Basic Configuration with Environment Credentials

version: v1
kind: Spicepod
name: dynamodb

datasets:
  - from: dynamodb:users
    name: users
    params:
      dynamodb_aws_region: us-west-2
    acceleration:
      enabled: true

Configuration with Explicit Credentials

version: v1
kind: Spicepod
name: dynamodb

datasets:
  - from: dynamodb:users
    name: users
    params:
      dynamodb_aws_region: us-west-2
      dynamodb_aws_auth: key
      dynamodb_aws_access_key_id: ${secrets:aws_access_key_id}
      dynamodb_aws_secret_access_key: ${secrets:aws_secret_access_key}
    acceleration:
      enabled: true

Configuration with Metadata-Only Credentials (ECS/EKS)

version: v1
kind: Spicepod
name: dynamodb

datasets:
  - from: dynamodb:users
    name: users
    params:
      dynamodb_aws_region: us-west-2
      dynamodb_aws_auth: iam_role
      dynamodb_aws_iam_role_source: metadata
    acceleration:
      enabled: true

Configuration with time_format

version: v1
kind: Spicepod
name: dynamodb

datasets:
  - from: dynamodb:users
    name: users
    params:
      dynamodb_aws_region: us-west-2
      time_format: 2006-01-02 15:04:05
    acceleration:
      enabled: true

Querying Nested Structures

DynamoDB supports complex nested JSON structures. These fields can be queried using SQL:

-- Query nested structs
SELECT metadata.registration_ip, metadata.user_agent 
FROM users 
LIMIT 5;

-- Query nested structs in arrays
SELECT address.city
FROM (
    SELECT unnest(addresses) AS address 
    FROM users
)
WHERE address.city = 'San Francisco';

Limitations

Example schema from a users table:

describe users;
+----------------+------------------+-------------+
| column_name    | data_type       | is_nullable |
+----------------+------------------+-------------+
| email          | Utf8            | YES         |
| id             | Int64           | YES         |
| metadata       | Struct          | YES         |
| addresses      | List(Struct)    | YES         |
| preferences    | Struct          | YES         |
| created_at     | Utf8            | YES         |
...
+----------------+------------------+-------------+

Streams

The DynamoDB Data Connector integrates with DynamoDB Streams to enable real-time streaming of table changes. This feature supports both initial table bootstrapping and continuous change data capture (CDC), so Spice can automatically detect and stream inserts, updates, and deletes from DynamoDB tables.

Basic Configuration

To enable streaming from DynamoDB, enable acceleration and set the refresh_mode to changes in your dataset configuration.

datasets:
  - from: dynamodb:my_table
    name: orders_stream
    acceleration:
      enabled: true
      engine: duckdb
      mode: file
      refresh_mode: changes

Configuration Parameters

Dataset Parameters

  • dynamodb_replication_ready_lag - Defines the maximum lag threshold before the dataset is reported as "Ready". Once the stream lag falls below this value, queries can be executed against the dataset. Default: 2s. (Previously ready_lag, still accepted as a deprecated alias.)

  • scan_interval - Controls the polling frequency for checking new records in the DynamoDB stream. Lower values provide more real-time updates but increase API calls. Higher values reduce API usage but may introduce additional latency.

Acceleration Parameters

  • snapshots - Optional. Controls snapshots behavior. Supported values are disabled (default), enabled, create_only, bootstrap_only.
  • snapshots_trigger - Optional. Determines type of trigger for creating snapshots. Supported values are time_interval (default) and stream_batches.
  • snapshots_trigger_threshold - Optional. Threshold value for snapshot creation. The format depends on the snapshots_trigger type:
    • When snapshots_trigger is stream_batches: a raw integer specifying the number of batches (e.g., 100, 1000).
    • When snapshots_trigger is time_interval: an integer with a time unit suffix (e.g., 10m, 30s, 1h).

See Acceleration snapshots for more details.

Metrics

The following Component Metrics are provided for monitoring streaming performance and health:

MetricTypeDescription
shards_activeGaugeCurrent number of active shards in the stream
records_consumed_totalCounterTotal number of records consumed from the stream
lag_msGaugeCurrent lag in milliseconds between stream watermark and the current time
errors_transient_totalCounterTotal number of transient errors encountered while polling from the stream
reinitializations_on_lag_exceeds_shard_retention_totalCounterTotal rebootstrap operations triggered due to expired shards

These metrics are not enabled by default, enable them by setting the metrics parameter:

datasets:
- from: dynamodb:user_events
  name: events
  acceleration:
    enabled: true
    refresh_mode: changes
  metrics:
   - name: shards_active
   - name: records_consumed_total
   - name: lag_ms
   - name: errors_transient_total
   - name: reinitializations_on_lag_exceeds_shard_retention_total

You can find an example dashboard for DynamoDB Streams in monitoring/grafana-dashboard.json.

Advanced Configuration

For production workloads requiring fine-tuned control over streaming behavior and performance characteristics:

datasets:
   - from: dynamodb:my_table
     name: orders_stream
     params:
        dynamodb_replication_ready_lag: 1s  # Dataset reports as Ready when lag is below 1 second
        scan_interval: 100ms                # Poll for new stream records every 100 milliseconds
     acceleration:
        enabled: true
        engine: duckdb
        mode: file
        refresh_mode: changes
        snapshots: enabled
        snapshots_trigger: stream_batches
        snapshots_trigger_threshold: 5  # Create snapshots every 5 batch updates
     metrics:
     - name: shards_active
     - name: records_consumed_total
     - name: lag_ms
     - name: errors_transient_total

Cookbooks