Importing from cloud document databases: DynamoDB, Firestore, Datastore, Cosmos DB
This page is for administrators whose organisation keeps data in one of the large cloud document databases and wants that data in Exponential as tables, and for developers who work on the readers. From Exponential 6.0.15 the kernel reads four services over their HTTP APIs, with PHP's curl extension and no vendor SDK:
| Service | Command | Reads | Key of a row |
|---|---|---|---|
| Amazon DynamoDB | exp:dynamodb:import | every table of a region | the table's partition key and sort key |
| Google Cloud Firestore (native mode) | exp:firestore:import | every top-level collection of a database | doc_id, the document's id |
| Google Cloud Datastore (and Firestore in Datastore mode) | exp:datastore:import | every kind of a namespace | doc_id, the key's name or id |
| Azure Cosmos DB for NoSQL | exp:cosmosdb:import | every container of a database | doc_id (the document's id), with the partition key when it is a top-level field |
What it is for. The level these services reach is the import: a command copies their documents into tables of the site's database or of any data table connection (MySQL, PostgreSQL, SQLite ...), where the data table layer, the templates and the reports read them like any other table. A connection of one of these engines is an import source: it keeps the server, the database and the name of the secret in one place, but it opens no database (no persistent class reads or writes it), and no site runs on them. A site database on a document store needs a document adapter like MongoDB's; that is not part of this work.
Contents
- Requirements
- Credentials and secrets
- A source connection
- Importing
- How documents become tables
- Each service
- Emulators
- How it is built
- Tests
Requirements
- PHP's curl extension (every request goes over HTTPS).
- PHP's openssl extension for a Google service account key (the token request is signed with RS256).
- A user of the service that may read: DynamoDB
ListTables,DescribeTable,Scan; Firestore and Datastore the role Cloud Datastore Viewer; Cosmos DB the account's read-only key (or the primary key). - The server's host in
datatable.ini [ConnectionSettings] AllowedHosts[]when that list is not empty.
Credentials and secrets
A password, key or token is never written into an INI file, a command line or a log. The connection and the
command name a secret of the kernel's secret store (Setup > Secrets, the secret store), or
env:VARIABLE for the environment of the PHP process. What the secret holds:
| Service | User | Secret |
|---|---|---|
| DynamoDB | the access key id (AKIA...) | the secret access key |
| Firestore, Datastore | - | the JSON key of a service account (the whole file), or an access token; nothing for an emulator |
| Cosmos DB | - | the account key (base64), read-only or primary |
Set the value in Setup > Secrets (tool datatable), or give the PHP process an environment variable and name it
env:AWS_SECRET_ACCESS_KEY. A service account's JSON key is pasted whole into the value field.
The readers keep the value in memory only; signatures (AWS Signature Version 4, the Cosmos DB master key signature) and tokens are made per request and never logged. An error names the service's message and the HTTP status, never a header.
A source connection
In the administration (Setup > Data table connections) or in datatable.ini:
[Connection_shop_dynamo]
Name=Shop (DynamoDB)
Engine=dynamodb
Database=eu-central-1
User=AKIAEXAMPLE
Secret=dynamo_reader
[Connection_app_firestore]
Engine=firestore
Database=my-project
Secret=firestore_reader
[Connection_legacy_datastore]
Engine=datastore
Database=my-project/shop
Secret=datastore_reader
[Connection_orders_cosmos]
Engine=cosmosdb
Server=myaccount.documents.azure.com
Database=shop
Secret=cosmos_shop_key| Engine | Server (when empty) | Database |
|---|---|---|
dynamodb | dynamodb.<region>.amazonaws.com | the region |
firestore | firestore.googleapis.com | project or project/database ((default) when none) |
datastore | datastore.googleapis.com | project or project/namespace |
cosmosdb | required: <account>.documents.azure.com | the database id |
Options (datatable.ini: TLS, SSLCA, VerifyTLS): tls=disabled for plain HTTP (an emulator), ssl_ca the CA
file of the server's certificate, verify_tls=disabled for an emulator's self-signed certificate. The connection's
test (Setup > Data table connections, Test) lists the collections and counts them. Opened as a database, the connection
says which command reads it.
Importing
Every command works like exp:couchdb:import: without --apply it shows the plan and writes nothing.
./console exp:dynamodb:import --source=shop_dynamo --list # the tables and their columns
./console exp:dynamodb:import --source=shop_dynamo --prefix=ddb_ # the plan
./console exp:dynamodb:import --source=shop_dynamo --prefix=ddb_ --apply # make the tables, copy the items
./console exp:firestore:import --source=app_firestore --tables=users --connection=archive --mode=replace --apply --format=json
./console exp:cosmosdb:import --server=myaccount.documents.azure.com --database=shop --secret=cosmos_shop_key --list| Option | Meaning |
|---|---|
--source | the source connection; or, without it, --server, --port, --database, --user (DynamoDB), --secret, --tls, --ssl-ca, --verify-tls |
--connection | where the tables go: site (the default) or a data table connection |
--tables | only these tables (a comma list, as --list names them) |
--prefix | put this in front of every table name |
--mode | create (new tables only, the default), append, replace (delete the rows first) |
--sample | the documents a table's columns are inferred from (500) |
--format | text or json (exp-dynamodb-import/1 ...) |
Exit code: 0 done (or planned); 1 a table or a row failed; 2 wrong options or no connection.
How documents become tables
A table's name is the collection's name in lower case, other characters _. Its columns are the top-level fields of
the first --sample documents, typed as the Couchbase and CouchDB imports type them:
| Values seen | Column |
|---|---|
| only integers | integer (bigint beyond 32 bits) |
| numbers | double |
| true / false | boolean (1 / 0) |
| text up to 255 characters | text (255), longer: memo |
| maps, arrays, sets, embedded entities | memo, as JSON |
| timestamps (Firestore, Datastore) | text Y-m-d H:i:s, UTC |
A field that only a later document has is left out: raise --sample. Sub-collections (Firestore) are not read.
DynamoDB numbers of more than 18 digits are kept as text.
Each service
DynamoDB. ListTables (100 a page), DescribeTable for the key schema, Scan with Limit 1000 and
ExclusiveStartKey. A scan reads every item and uses read capacity: on provisioned tables, import at a quiet hour
or raise the capacity for the run. Temporary credentials (a session token) are not supported yet.
Firestore. listCollectionIds, then the documents of each collection in the order of their names, 1000 a page.
The project's (default) database unless the Database names another.
Datastore. A kindless query of __kind__ lists the kinds (Datastore's own, __*__, are left out); the entities
are read by a query of their kind, 1000 a page, by cursor. A key value becomes its path (Customer:c1).
Cosmos DB. The containers of the database, then each container's read feed, 1000 a page, by
x-ms-continuation. _rid, _self, _etag, _attachments and _ts are left out. A read uses request units:
on a provisioned account, mind its throughput.
Emulators
The readers work against the local emulators of the services, which is how they are tested; never point them at an emulator on a production host.
| Service | Emulator | Command |
|---|---|---|
| DynamoDB | DynamoDB Local (amazon/dynamodb-local, port 8000) | --server=http://localhost:8000 --database=us-east-1 --user=local --secret=env:DDB_LOCAL_KEY (any keys) |
| Firestore | the Firestore emulator (gcloud emulators firestore start, port 8080) | --server=http://localhost:8080 --database=demo-project (no secret) |
| Datastore | the Datastore emulator (gcloud beta emulators datastore start, port 8081) | --server=http://localhost:8081 --database=demo-project |
| Cosmos DB | the Linux emulator (mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator, port 8081) | --server=localhost:8081 --verify-tls=disabled --database=shop --secret=env:COSMOS_EMULATOR_KEY (its published key) |
How it is built
| File | What |
|---|---|
kernel/classes/cloudnosql/expcloudnosqlhttp.php | the HTTP client (curl, kept connection, response headers) |
kernel/classes/cloudnosql/expcloudnosqlreader.php | the shared reader: tables, sampling, rows, in the vocabulary of expAccessReader |
kernel/classes/cloudnosql/expdynamodbreader.php | DynamoDB, with AWS Signature Version 4 (sign()) |
kernel/classes/cloudnosql/expgoogleauth.php | the Google token (service account JWT) and the Firestore / Datastore values |
kernel/classes/cloudnosql/expfirestorereader.php, expdatastorereader.php | Firestore, Datastore |
kernel/classes/cloudnosql/expcosmosdbreader.php | Cosmos DB, with the master key signature (authorization()) |
kernel/classes/cloudnosql/expcloudnosqlsources.php | a connection or the command's options made into a reader |
kernel/private/classes/commands/exp{dynamodb,firestore,datastore,cosmosdb}import.php | the commands (on top of exp:couchbase:import) |
The tables are made and filled by the Access import's engine, expAccessImport, as for every other import.
Tests
tests/tests/kernel/classes/cloudnosql/expCloudNoSQLReadersTest.php (suite kernel, no server): the AWS test
suite's Signature Version 4 vector, Microsoft's Cosmos DB signature example, a service account JWT verified with its
public key, and each reader paging through more than one page of a stand-in service.
php vendor/bin/phpunit tests/tests/kernel/classes/cloudnosql/expCloudNoSQLReadersTest.phpThe live tests (tests/tests/kernel/classes/cloudnosql/live/expCloudNoSQLImportLiveTest.php) run against the
emulators, each skipped without its URL:
EXP_TEST_DYNAMODB_URL=http://127.0.0.1:8000 EXP_TEST_COSMOSDB_URL=http://127.0.0.1:8081 \
EXP_TEST_FIRESTORE_URL=http://127.0.0.1:8080 EXP_TEST_DATASTORE_URL=http://127.0.0.1:8081 EXP_TEST_DATASTORE_PROJECT=exp-live \
php vendor/bin/phpunit tests/tests/kernel/classes/cloudnosql/live/Measured on 2026-11-28 with PHP 8.5 (podman): DynamoDB Local 3.3.2 (1,200 items over several Scan pages), the
Cosmos DB emulator vnext-preview with the API for NoSQL over HTTP (250 documents read by the feed), and the
Firestore (130 documents) and Datastore (120 entities by cursor) emulators of google-cloud-cli: every record imported,
4 tests, 402 assertions. The Firestore emulator lists collections only for its admin: without credentials the reader
sends its token (Bearer owner). A Datastore kind becomes a table of a lower-case name (Order is order). The
services themselves (AWS, Google Cloud, Azure) were not reached; they answer the same API with credentials.