table import
Use dynomate-cli table import to write items to a DynamoDB table from a file, S3, another table or standard input.
It uses the same checks as Add / Import Items in the app. In a DNML request, use dynamodb.import with requests run.
Import a File
This file contains two orders for an Orders table with the key accountId and orderId:
[
{"accountId": "account#42", "orderId": "order#9820", "status": "PENDING", "total": 18.25},
{"accountId": "account#51", "orderId": "order#9821", "status": "PAID", "total": 64}
] Give the profile, the destination table and the source:
$ dynomate-cli table import --profile commerce-dev --table-arn arn:aws:dynamodb:ap-southeast-2:000000000000:table/Orders --from-file ./new-orders.json
Import completed
Items: 2 processed, 2 written, 0 skipped, 0 failed Destination
Identify the destination table:
- By ARN:
--table-arn arn:PARTITION:dynamodb:REGION:ACCOUNT:table/NAME. - By name:
--table NAME --region REGION, and optionally--account.
$ dynomate-cli table import --profile commerce-dev --table Orders --region ap-southeast-2 --from-file ./new-orders.json
Import completed
Items: 2 processed, 2 written, 0 skipped, 0 failed
Use --region and --account only with --table. For a local endpoint, the default account is 000000000000.
Profiles
You must give --profile, a profile from your AWS config and credentials files. The CLI uses its credentials, and its endpoint_url if it has one.
Use --source-profile to copy items from a different account.
Endpoints saved in the app do not apply, because the command does not read the app data directory. For DynamoDB Local, set the endpoint and placeholder keys on the profile:
[profile commerce-dev]
region = ap-southeast-2
endpoint_url = http://localhost:8000 Sources
Use exactly one source:
--from-file PATH: a local file. If the extension is not.jsonor.csv, add--format.--from-s3 arn:aws:s3:::BUCKET/KEYwith--format.--from-table NAME --source-region REGION, or--from-table-arn ARN.--json-stdinwith a JSON array of items.
The source cannot be the destination table, also through a different profile with the same ARN and endpoint.
Formats
The source is a JSON array or a CSV file with a header row. Each item must contain all key attributes of the destination. The format rules are the same as in the app.
Conflict Mode
--conflict-mode sets what to do if a key already exists in the table:
overwrite(default): replaces the item with the full incoming item.skip-existing: keeps the item and counts it as skipped.
Preflight
Each import starts with a preflight check of key names and types, malformed input and duplicate keys. If the check finds blockers, the CLI writes nothing.
To do only the check, add --preflight-only:
$ dynomate-cli table import --profile commerce-dev --table-arn arn:aws:dynamodb:ap-southeast-2:000000000000:table/Orders --from-file ./new-orders.json --preflight-only
Preflight: new-orders.json (file)
Items: 2
Valid: 2 · Invalid: 0 · Duplicate keys: 0
Showing 2 of 2 items
- accountId="account#42"|orderId="order#9820"
- accountId="account#51"|orderId="order#9821"
Preflight does not look for existing keys. --conflict-mode controls them.
Output
The default --output pretty prints the summaries above. --output json prints one JSON document:
status:completed,failedorcancelled.totalItems,processedItems,writtenItems,skippedItems,failedItems: item counts.errorMessage: the reason for a failure, ornull.
The summary goes to standard output. If the import or preflight fails, it goes to standard error.
Options
| Option | Default | Description |
|---|---|---|
--profile <PROFILE> | Required | The AWS profile for the destination. |
--table <TABLE> | The destination table name. | |
--table-arn <TABLE_ARN> | The destination table ARN. | |
--region <REGION> | The region for --table. | |
--account <ACCOUNT> | Profile's account | The 12-digit account in the table ARN. |
--from-file <FROM_FILE> | A local JSON or CSV file. | |
--from-s3 <FROM_S3> | An S3 object ARN. | |
--s3-region <S3_REGION> | Destination region | The region of the S3 bucket. |
--from-table <FROM_TABLE> | The source table name. | |
--from-table-arn <FROM_TABLE_ARN> | The source table ARN. | |
--source-region <SOURCE_REGION> | The region for --from-table. | |
--source-account <SOURCE_ACCOUNT> | Source profile's account | The account for --from-table. |
--json-stdin | Reads items from standard input. | |
--source-profile <SOURCE_PROFILE> | --profile | The AWS profile for an S3 or table source. |
--format <FORMAT> | From file extension | The source format: json or csv. |
--conflict-mode <CONFLICT_MODE> | overwrite | overwrite or skip-existing. |
--preflight-only | Checks the source and writes nothing. | |
--output <OUTPUT> | pretty | The result format: pretty or json. |
-h, --help | Prints help. |
Exit Codes
| Code | Meaning |
|---|---|
0 | The import completed, or --preflight-only found no blockers. |
1 | The import or preflight failed, or the CLI cannot read the source or destination. |
2 | The arguments are not valid, for example --region with --table-arn. |