Skip to content

Instantly share code, notes, and snippets.

@koonagi
Created December 24, 2020 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koonagi/d89ff4eb35738326b4c340a9c243d192 to your computer and use it in GitHub Desktop.
Save koonagi/d89ff4eb35738326b4c340a9c243d192 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# != 4 ]; then
echo "+++ Argument Error +++"
echo Usage: ./s3select_cli.sh "<s3_bucket_name>" "<s3_Object_key>" "<file_format Parquet|CSV>" "<SQL>"
echo Example: ./s3select_cli.sh nyc-tlc misc/uber_nyc_data.csv CSV "select * from s3object limit 10"
exit 1
fi
BucketName=$1
KeyName=$2
Format=$3
SQL=$4
aws s3api select-object-content --bucket ${BucketName} --key "${KeyName}" --expression "${SQL}" --expression-type 'SQL' --input-serialization '{"'${Format}'": {}, "CompressionType": "NONE"}' --output-serialization '{"CSV": {}}' "tmp_output.csv" && cat tmp_output.csv && rm tmp_output.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment