Direkt zum Inhalt

How do I resolve the unexpected token error when I import data from Amazon S3 to DynamoDB?

Lesedauer: 1 Minute
1

When I import data from Amazon Simple Storage Service (Amazon S3) to Amazon DynamoDB, the import fails, and I get an unexpected token error message.

Resolution

If you use the Import from S3 feature in DynamoDB, then you might get an error message similar to the following:

"Unexpected token. Remainder of the file will not be processed."

Review the data format, compression type, and path of your Amazon S3 objects. The data in your Amazon S3 bucket must be in the CSV, DynamoDB JSON, or ION format. If you compress your data, then use only GZIP or ZSTD.

After you review your data, use the DynamoDB console to request an import. To track the status of your import, view Imports from S3 in the DynamoDB console.

AWS OFFICIALAktualisiert vor 3 Monaten
1 Kommentar

If you are confident that your input files have the correct DDB JSON import format and you have correctly configured the import job format and file compression settings, this problem can arise from invalid JSON items.

Try downloading the S3 object that is failing to import and using jq to parse it to detect invalid JSON.

This bash snippet will process each line in the file, printing any parsing errors jq encounters as debug messages:

# INFO: Tested working with jq-1.8.1 on Amazon Linux 2
cat your_s3_object_file.jsonl | jq -R 'try fromjson catch debug | empty''

Input used to test this method (note, 2nd line is valid, first and 3rd are not):

"\m"
"\n"
"\o"

Output observed (note, final error arises from endline-terminated file containing a single empty string input)

["DEBUG:","Invalid escape at line 1, column 4 (while parsing '\"\\m\"')"]
["DEBUG:","Invalid escape at line 1, column 4 (while parsing '\"\\o\"')"]
["DEBUG:","Expected JSON value (while parsing '')"]
beantwortet vor 3 Monaten