Skippr is now Manifold.

Skip to content

Quickstart: S3 to Athena ​

In about ten minutes you will load public sample JSON from S3 into your own S3 bucket as Parquet, registered as a table in the AWS Glue Data Catalog, and query it in Amazon Athena.

Mfd reads the JSON, infers its schema, creates the Glue database and table for you, and writes the data. You only provide a bucket and permissions.

Before you begin ​

You need:

  • Mfd installed. Check with mfd --version, or python -c "import mfd" if you use Python. See Install.
  • An AWS account and credentials for an IAM principal that can:
    • read s3://mfd-public-sample-data/bike-hire/ (s3:ListBucket, s3:GetObject);
    • read and write your output bucket (s3:ListBucket, s3:GetObject, s3:PutObject, s3:DeleteObject);
    • create and update Glue databases, tables, and partitions;
    • run Athena queries in your workgroup.
  • An S3 bucket for the output in the region you will query from. This guide uses one bucket, your-output-bucket, for both the Parquet data and Athena query results.

Export your credentials, then create an empty working directory. Mfd reads mfd.yml from the current directory, so run every command from there.

bash
export AWS_ACCESS_KEY_ID="your-access-key-id"
export AWS_SECRET_ACCESS_KEY="your-secret-access-key"
export AWS_DEFAULT_REGION="us-east-1"

mkdir mfd-athena && cd mfd-athena

Any standard AWS credential source works instead of access keys, such as AWS_PROFILE or an instance role. Use the region your output bucket and Athena workgroup live in.

1. Describe the pipeline ​

A pipeline has a source (where data comes from) and a destination (where it lands). For Athena, set glue_database_name on the Athena data sink so compact can publish tables to the Glue Data Catalog. Each tab below writes the same mfd.yml. Replace your-output-bucket with your bucket name.

python
from mfd import Config, DataSinkAthena, DataSourceS3, LocalStorage, Pipeline

cfg = Config().workspace("quickstart").storage(LocalStorage())
sample = cfg.data_source(
    "sample",
    DataSourceS3(s3_bucket="mfd-public-sample-data", s3_prefix="bike-hire"),
)
athena = cfg.data_sink(
    "athena",
    DataSinkAthena(
        s3_bucket="your-output-bucket",
        s3_prefix="data/bikehire",
        glue_database_name="mfd_quickstart",
        athena_workgroup_name="primary",
        athena_results_s3_bucket="your-output-bucket",
    ),
)
cfg.pipeline("bikehire", Pipeline(data_source=sample, data_sink=athena))
cfg.save("mfd.yml")
bash
mfd --workspace quickstart --storage-mode local connect data-source s3 \
  --pipeline bikehire \
  --name sample \
  --s3-bucket mfd-public-sample-data \
  --s3-prefix bike-hire

mfd connect data-sink athena \
  --pipeline bikehire \
  --name athena \
  --s3-bucket your-output-bucket \
  --s3-prefix data/bikehire \
  --glue-database-name mfd_quickstart \
  --athena-workgroup-name primary \
  --athena-results-s3-bucket your-output-bucket
yaml
mfd:
  workspace: quickstart
  mfd_el_storage_mode: local

pipelines:
  bikehire:
    data_source: data_sources.sample
    data_sink: data_sinks.athena

data_sources:
  sample:
    S3:
      s3_bucket: mfd-public-sample-data
      s3_prefix: bike-hire

data_sinks:
  athena:
    Athena:
      s3_bucket: your-output-bucket
      s3_prefix: data/bikehire
      glue_database_name: mfd_quickstart
      athena_workgroup_name: primary
      athena_results_s3_bucket: your-output-bucket

What the settings mean:

  • athena_results_s3_bucket is a bucket name, not an s3:// URI.
  • glue_database_name on the Athena destination names the Glue database the table is registered in on the first compact.
  • LocalStorage() (mfd_el_storage_mode: local) keeps Mfd's own state, such as the discovered schema and how far it has read, in ./data. That is fine for a trial; for production, see Manifold Store.

After you save the file, check it. Doctor validates mfd.yml; it does not connect, so it does not replace discover.

python
import mfd

s = mfd.Session(mfd.Config.discover().get_pipeline("bikehire"))
s.doctor()
bash
mfd doctor

2. Discover the schema ​

python
import mfd

s = mfd.Session(mfd.Config.discover().get_pipeline("bikehire"))
s.discover()
bash
mfd discover --pipeline bikehire
mfd schema --pipeline bikehire

discover samples the JSON objects under the prefix and records each field's name and type. It does not write to your bucket. mfd schema prints the fields it found, which become the columns of your Athena table.

The first command that uses a connector downloads it, so the first run takes a little longer.

3. Sync ​

python
import mfd

s = mfd.Session(mfd.Config.discover().get_pipeline("bikehire"))
s.sync(once=True)
bash
mfd sync --pipeline bikehire --once

Sync reads every object under the prefix and writes it to Mfd's write-ahead log (WAL) first. A crash retries that committed batch. Athena overwrites the same files, so you do not get a second copy. Mfd then creates the mfd_quickstart Glue database and the bikehire table if they do not exist, and writes Parquet files under s3://your-output-bucket/data/bikehire/bikehire/.

--once (once=True) runs a single pass and exits. Without it, sync keeps running and checks the source for new objects on a schedule (every 900 seconds by default; set sync_frequency_seconds on the pipeline to change it).

Check it worked ​

Open the Athena query editor in the same region, select the primary workgroup and the mfd_quickstart database, and run:

sql
SELECT count(*) AS row_count FROM mfd_quickstart.bikehire;

You should see a non-zero row_count. Then look at the data:

sql
SELECT * FROM mfd_quickstart.bikehire LIMIT 10;

The columns match the fields mfd schema printed in step 2. The table is named after the pipeline, bikehire.

Run mfd sync --pipeline bikehire --once again and repeat the count. It does not change: Mfd remembers which objects it has already read.

Troubleshooting ​

  • AccessDenied reading mfd-public-sample-data — your credentials are missing or lack S3 read access. Run aws sts get-caller-identity to confirm which principal Mfd uses, then grant s3:ListBucket and s3:GetObject on the sample bucket.
  • AccessDenied on a Glue CreateDatabase, CreateTable, or partition call — the principal cannot manage the Glue Data Catalog. Grant Glue create, get, and update permissions on the mfd_quickstart database and its tables.
  • AccessDenied writing to your-output-bucket — grant s3:PutObject (and s3:ListBucket, s3:GetObject, s3:DeleteObject) on the bucket.
  • Athena cannot find mfd_quickstart — the console is in a different region from the one you synced to. Switch to the region in AWS_DEFAULT_REGION.
  • Athena asks for a query result location — the primary workgroup has no output location. In the workgroup or query editor settings, set it to s3://your-output-bucket/athena-results/.
  • The count is zero or the table is missing after sync — sync did not finish. Rerun with --log (or --log debug) to see each step and the error that stopped it. Records that fail to convert go to a deadletter instead of the table.
  • The first run hangs while fetching a connector — the machine cannot reach install.manifold.soundingworks.uk over HTTPS. See Install.

For more, see Troubleshooting.

Next steps ​