0

I need a CLI alternative similar to the example here in Dashboard link but with Json as input & output serialization types.

I have tried running the following for Json in AWS cloud shell to get the output printed on the terminal,but end up getting an error.

aws s3api select-object-content --bucket "my-bucket" --key jobs/test.json --expression "SELECT * FROM s3object s LIMIT 5" --expression-type 'SQL' --input-serialization "{"JSON":{"Type": "DOCUMENT"},"CompressionType": "None"}" --output-serialization "{"JSON": {Type: 'DOCUMENT'}}" /dev/stdout

Error: Error parsing parameter '--input-serialization': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) JSON received: {JSON:{Type: DOCUMENT},CompressionType: None}

I see a lot of options for csv format ,but unable to find the same for Json.

Thank you in advance.

Note:Running on AWS cloudshell which is basically on Linux.

FYI: The following is the dashboard alternative of the input & output serialization I am trying to achieve here.

enter image description here

sarav
  • 47
  • 9

1 Answers1

2

Use single quotes ' to enclose the entire JSON string, if you are using linux/macOS terminal. In powershell, use \ to escape the double quotes.

like this -

aws s3api select-object-content --bucket "my-bucket" --key jobs/test.json --expression "SELECT * FROM s3object s LIMIT 5" --expression-type 'SQL' --input-serialization '"{"JSON":{"Type": "DOCUMENT"},"CompressionType": "None"}"' --output-serialization '"{"JSON": {Type: "DOCUMENT"}}"' /dev/stdout

Note: If you have any single quotes inside your JSON string, needs to be escaped with backslash \.

vman
  • 163
  • 2
  • 11
  • Still I am getting the same error :( – sarav Mar 22 '22 at 14:30
  • 1
    Can you try the suggestions given here according to your shell? [aws cli quotation marks usage](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-quoting-strings.html) – vman Mar 22 '22 at 14:38
  • 1
    This command is double quoting the JSON documents, you want `--input-serialization '{"JSON":{"Type": "DOCUMENT"},"CompressionType": "None"}' --output-serialization '{"JSON": {"Type": "DOCUMENT"}}'` (note the lack of quotes around the brackets, and the quotes around the second `Type` – Anon Coward Mar 22 '22 at 15:26
  • Thanks @AnonCoward @vman . That error is sorted now .. I am trying something with the `--input-serialization '{"JSON":{"Type": "LINES"},"CompressionType": "NONE"}' --output-serialization '{"JSON": {"Type": "LINES"}}' /dev/stdout` I am getting the following error. "Parameter validation failed: Unknown parameter in OutputSerialization.JSON: "Type", must be one of: RecordDelimiter" Added a screenshot to the post what I exactly need in my input/output serialization. Can you help me validate the same? – sarav Mar 24 '22 at 07:36
  • 1
    **The final working solution:** `aws s3api select-object-content --bucket "my-bucket" --key jobs/test.json --expression "SELECT * FROM s3object s LIMIT 5" --expression-type 'SQL' --input-serialization '{"JSON":{"Type": "DOCUMENT"},"CompressionType": "NONE"}' --output-serialization '{"JSON":{"RecordDelimiter":"n"}}' /dev/stdout` Credits to my colleague Amit CS(wish I could tag him here) for figuring out the missing pieces. – sarav Mar 24 '22 at 12:18