Setup
Let’s first create a virtual environment:ipython to run the commands in the rest of the guide, which you can launch by running:
Listing files in an S3 bucket
Let’s start by listing all the files in an S3 bucket that contains Amazon reviews. To do this, we can use thes3 table function and pass in the path to a file or a wildcard to a set of files.
We’re also going to use the One input format so that the file isn’t parsed, instead a single row is returned per file and we can access the file via the _file virtual column and the path via the _path virtual column.
Querying files in an S3 bucket
Next, let’s learn how to query those files. If we want to count the number of rows in each of those files, we can run the following query:DESCRIBE clause:
Querying files in a private S3 bucket
If we’re querying files in a private S3 bucket, we need to pass in an access key and secret. We can pass in those credentials to thes3 table function:
This query won’t work because it’s a public bucket!