Beginner14 min read

How to Export a DynamoDB Table to CSV (4 Ways)

DynamoDB has no native "export to CSV" button. Every value comes back wrapped in DynamoDB's marshaled JSON ({"S": "..."}, {"N": "123"}, {"M": {...}}), and a table can hold nested maps, lists, and sets with no obvious flat-column representation.

So "export DynamoDB to CSV" is really two problems: get the items out, then flatten the typed JSON into rows. The CLI and the managed S3 export only do the first step.

How do I export a DynamoDB table to CSV?

Pick by table size and how often you need it:

  • Filtered or ad-hoc CSV (some items, some columns): a GUI export (Method 1) or a script. AWS's free NoSQL Workbench also exports query results as CSV, one page at a time.
  • Small table, terminal-only: AWS CLI scan + jq (Method 2).
  • Large table (GBs+): DynamoDB export to S3 (Method 3), then write CSV from it with Athena. The export runs asynchronously, consumes no read capacity, and can be filtered to a subset, but it writes DynamoDB JSON, not CSV.
  • Unattended, a nightly job: a short script (Method 4).

Method 1: export from DynoTable

DynoTable treats export as part of browsing: run or filter a query, press ⌘⇧E (or the Export button in the tab toolbar), pick File, CSV and a scope, then Export:

  • Formats: CSV (one row per item, with headers), JSON, and NDJSON. JSON/NDJSON come as Values: Plain values ("count": 3) or DynamoDB-JSON when you need a lossless round-trip that preserves large numbers (DynamoDB-JSON needs the full-filter-match scope).
  • Scopes: the currently loaded rows, just your selection, or the full filter match: every item your query matches, streamed straight from DynamoDB rather than only what's on screen.
  • Destination: a file, the clipboard, or Amazon S3, picked first. The S3 destination has DynamoDB write the query's matching items to your bucket from the table's point-in-time recovery backup, with no read capacity used: a filtered version of Method 3 that still writes DynamoDB JSON or Ion, not CSV. For one-off grabs, right-click a row and Copy as… puts CSV, JSON, NDJSON, or DynamoDB-JSON straight on the clipboard, no dialog.
DynoTable's export dialog, first step: send the rows to a file, the clipboard, or Amazon S3.
DynoTable's export dialog, first step: send the rows to a file, the clipboard, or Amazon S3.

In the CSV, type descriptors are unwrapped, a nested map, list or set lands in one cell as JSON (sets as JSON arrays, so their order isn't meaningful), and renamed columns flow through to the headers.

Large exports detach and run in the background, streamed to disk row by row and surviving tab switches and even an app reload, so a multi-gigabyte export never has to fit in memory.

It's a desktop DynamoDB client, the same tool you already use to browse the table; see how it compares to other DynamoDB GUIs. When would you not use it? When the export must run unattended in a pipeline; that's what the script route (Method 4) is for.

Method 2: AWS CLI scan + jq

For a small table you can scan it and reshape the output with jq. A Scan reads every item in the table and returns it in pages of up to 1 MB; the CLI follows pagination for you automatically (AWS docs: Scanning tables).

aws dynamodb scan --table-name MyTable --output json \
  | jq -r '.Items[] | [.id.S, .name.S, .price.N] | @csv' \
  > out.csv

The catch is in that jq line: you hand-write .id.S, .name.S, .price.N, reaching past each attribute's type descriptor (S, N, B, BOOL, M, L, SS, NS, BS) to get the raw value. That's manageable for a flat table with three string columns. It falls apart the moment you have:

  • Nested maps/lists: {"M": {...}} or {"L": [...]} have no single column to flatten into, and @csv rejects them.
  • Sets: {"SS": ["a","b"]} is an array, not a scalar.
  • Sparse attributes: DynamoDB is schemaless, so item A may have a price and item B may not. A fixed column list silently drops columns it doesn't name.

This version handles all three. It builds the header from every attribute name in the scan, writes binary values as plain base64, sets as ;-joined values, and maps and lists as JSON in one cell (their inner type descriptors included):

aws dynamodb scan --table-name MyTable --output json > scan.json
jq -r '(.Items | map(keys) | add | unique) as $cols
  | $cols, (.Items[] | [$cols[] as $c | .[$c]
      | if . == null then ""
        else to_entries[0]
          | if .key == "S" or .key == "N" or .key == "B" then .value
            elif .key == "BOOL" then (.value | tostring)
            elif .key == "NULL" then ""
            elif .key == "SS" or .key == "NS" or .key == "BS" then (.value | join(";"))
            else (.value | tojson) end
        end])
  | @csv' scan.json > out.csv

There is also no --output csv: the CLI's output formats are json, yaml, yaml-stream, text, table, and off, none of which understand DynamoDB types. So you still need jq (or a script) to strip the type tags.

To export a larger table this way without it taking all day, parallelize the scan with --segment / --total-segments (AWS docs: Parallel scan: DynamoDB "assigns items to segments by applying a hash function to each item's partition key", so segments can be uneven), and read pagination so you don't stop at the first 1 MB page.

Method 3: DynamoDB export to S3 (large tables)

For large tables, the managed export to Amazon S3 is the right tool. It exports a snapshot from any point in your point-in-time recovery (PITR) window, so PITR must be enabled on the table first, or the export fails with PointInTimeRecoveryUnavailableException.

It runs asynchronously and consumes no read capacity units (AWS docs: "Exports are asynchronous, they don't consume read capacity units (RCUs) and have no impact on table performance and availability"; "You need to enable PITR on your table to use the export functionality").

The console's Exports to S3 action is a front end for the same API, with the same PITR requirement and the same JSON output. The command below exports the full table:

aws dynamodb export-table-to-point-in-time \
  --table-arn arn:aws:dynamodb:us-east-1:123456789012:table/MyTable \
  --s3-bucket my-export-bucket \
  --export-format DYNAMODB_JSON

To export a subset, add a filter: the CLI's --filter-specification, or the console's optional filter step (filtered export). It takes a key condition on one partition-key value, a filter expression, and a projection:

  --filter-specification '{"KeyConditionExpression": "PK = :p",
    "FilterExpression": "#s = :open", "ProjectionExpression": "PK, SK, #s, #t",
    "ExpressionAttributeNames": {"#s": "status", "#t": "type"},
    "ExpressionAttributeValues": {":p": {"S": "ACCOUNT#42"}, ":open": {"S": "open"}}}'

An older AWS CLI rejects --filter-specification with Unknown options; update the CLI if you see that.

Only the key condition reduces the data DynamoDB reads and bills; a filter expression is applied after the read. DynoTable's S3 export builds this filter from your query.

The expressions follow the usual rules, so alias reserved words like status and type through ExpressionAttributeNames. DynamoDB validates the filter before the export starts and rejects the whole request with a ValidationException otherwise.

The export does not output CSV. It writes DynamoDB JSON or Amazon Ion only, as gzipped files in JSON-lines format (one item per line), plus manifest files (AWS docs: export output format: data files are written as .json.gz, "the format is JSON lines", alongside manifest-summary.json / manifest-files.json).

The usual CSV hop is Athena, which AWS notes "will parse this format automatically" (export output format). Point a table at the export's data folder, then select the columns you want. The lowercase s and n in the struct match the export's "S" and "N" keys because the OpenX JSON SerDe ignores key case by default:

CREATE EXTERNAL TABLE tickets_export (
  Item struct<id:struct<s:string>, status:struct<s:string>, priority:struct<n:string>>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION 's3://my-export-bucket/AWSDynamoDB/<export-id>/data/';

SELECT Item.id.s AS id, Item.status.s AS status, Item.priority.n AS priority
FROM tickets_export;

Athena writes every SELECT result as a CSV file, with a header row, in your query-result location, which you can download from the console.

For a big result, wrap the SELECT in UNLOAD with WITH (format = 'TEXTFILE', field_delimiter = ','): it writes gzipped, comma-delimited files to an empty S3 prefix you name.

AWS documents column headers only for a plain SELECT result and says nothing about quoting in TEXTFILE output. Expect no header row, and check a value that contains a comma before you rely on the files. When values can contain commas, use the SELECT result.

Or roll your own: decompress the .gz files, parse each JSON line, and flatten it (same flattening problem as every other method).

Method 4: a quick script (boto3 / Node)

When the export must run unattended (a nightly job, a CI step), a small script beats everything above. The AWS SDKs unmarshall the typed JSON for you: boto3's resource interface and the JS SDK's DynamoDBDocumentClient return plain values ({"price": Decimal("2000")} in boto3) instead of {"price": {"N": "2000"}} (boto3's resource interface makes "the data typing implicit", per the AWS Python guide; the JS DocumentClient "converts annotated response data to native JavaScript types", per @aws-sdk/lib-dynamodb).

import boto3, csv, json
from decimal import Decimal

def cell(v):
    if isinstance(v, (set, frozenset)):          # SS / NS: unordered, so sort
        return ";".join(sorted(str(x) for x in v))
    if isinstance(v, (dict, list)):              # M / L: JSON in one cell
        return json.dumps(v, default=str)
    if isinstance(v, Decimal):                   # N: keep every digit
        return str(v)
    return v

table = boto3.resource("dynamodb").Table("MyTable")
rows, resp = [], table.scan()
rows += resp["Items"]
while "LastEvaluatedKey" in resp:                  # paginate to the end
    resp = table.scan(ExclusiveStartKey=resp["LastEvaluatedKey"])
    rows += resp["Items"]

columns = sorted({k for r in rows for k in r})     # union of attributes
with open("out.csv", "w", newline="") as f:
    w = csv.DictWriter(f, fieldnames=columns)
    w.writeheader()
    for r in rows:
        w.writerow({k: cell(r[k]) if k in r else "" for k in columns})

The cell() helper makes the two decisions the SDK can't: nested maps and lists become JSON in one cell (dot-path columns like address.city are the alternative), and a missing attribute becomes an empty cell. Numbers inside a map or list are written as JSON strings ({"zip": "75001"}), which keeps every digit but drops the number type. Don't drop the LastEvaluatedKey loop: a single scan() call returns only the first 1 MB page, so without it you silently export part of the table.

Same caveat as Method 2: a full-table scan here still consumes read capacity and competes with live traffic. For a big table, prefer Method 3 and reshape the dump.

Gotchas: DynamoDB JSON vs flat CSV

Whichever method you pick, the same handful of mismatches between DynamoDB's data model and a flat CSV will bite you:

  • Type descriptors. Raw API / CLI / S3-export output wraps every value ({"S": "..."}, {"N": "123"}). You either unwrap it via an SDK or strip the descriptor yourself. The full set is S, N, B, BOOL, NULL, M, L, SS, NS, BS; see DynamoDB data types.
  • Nested maps and lists (M, L) can nest up to 32 levels deep (AWS docs: data types: list and map "can be nested within each other, to represent complex data structures up to 32 levels deep") and have no natural single-column form. Decide up front: JSON-encode the cell, or explode nested keys into dot-pathed columns (address.city).
  • Sets (SS/NS/BS) are unordered collections, not scalars. AWS warns "the order of the values within a set is not preserved" (data types), so flatten to a delimited string and don't rely on element order.
  • Sparse attributes. DynamoDB is schemaless, so two items can have different attributes. There is no fixed column set; union the keys across all items or columns will misalign. This is a direct consequence of single-table design, where one table holds several entity shapes.
  • Pagination. Scan (and Query) return at most 1 MB per call. If you don't loop on LastEvaluatedKey you'll silently export only the first page. See pagination.
  • Number precision. DynamoDB numbers carry up to 38 digits of precision and travel as strings (AWS docs: data types: "Numbers can have up to 38 digits of precision"; "All numbers are sent across the network to DynamoDB as strings"). Spreadsheet software may coerce long numbers or IDs into floats and lose digits. In Excel, don't double-click the file: use Data → From Text/CSV and set those columns to Text (Microsoft support).

FAQ

What's the fastest way to export a DynamoDB table to CSV? It depends on the table. For a small table, CLI scan + jq. For a large one, the S3 export plus an Athena SELECT. For a filtered or ad-hoc subset, a GUI export: in DynoTable, filter the table, press ⌘⇧E, pick CSV, and choose a scope, from the selected rows up to every item the filter matches.

How do I export a DynamoDB table to CSV with the AWS CLI? Scan the table and reshape the output with jq (Method 2): aws dynamodb scan → jq to strip each value's type descriptor → @csv. There's no DynamoDB-aware --output csv, so you always do the type-stripping yourself; Method 2 shows a jq filter that also handles nested maps, lists, sets and sparse attributes.

Can I export a DynamoDB table directly to CSV from AWS? Not a whole table in one step. The managed S3 export produces DynamoDB JSON or Amazon Ion, never CSV, and NoSQL Workbench exports query results to CSV one page at a time. Past that you need a conversion step: CLI + jq, a script, Athena over the S3 dump, or a GUI that does the flattening for you.

How do I export an entire DynamoDB table without affecting production? Use the export to S3 feature (Method 3). It runs asynchronously and consumes no read capacity units, so it doesn't compete with live traffic, unlike a Scan, which is metered against your table's throughput (AWS docs). It requires PITR to be enabled. To export only some items, the API, CLI and console take a filter, and DynoTable's S3 export builds one from your query.

How do I export DynamoDB to S3 as CSV? The managed export only writes DynamoDB JSON / Ion to S3, so "to CSV" is a second hop: register the export's data folder as an Athena table and run a SELECT (its result is a CSV file) or an UNLOAD with format = 'TEXTFILE'. There's no --export-format CSV.

How do I export DynamoDB to Excel? Export to CSV first (any method above), then load it with Excel's Data → From Text/CSV and set long numeric IDs to Text so they aren't coerced to floats. There's no direct .xlsx export from DynamoDB; DynoTable saves the current view straight to a spreadsheet-ready CSV.

Why does my exported JSON have {"S": ...} and {"N": ...} everywhere? That's DynamoDB's wire format: each value is tagged with a type descriptor. Unmarshall it with an SDK, the DynamoDB JSON converter, or a GUI before writing CSV. The wire format is the same whether the data came from the API, the CLI, or the S3 export.

Browse, filter, and export your own tables to CSV with DynoTable, or unwrap a sample of DynamoDB JSON in the JSON converter first.

By Dmitriy · Updated