Back
Database Management

Reliable database management for modern, high-performance systems.

Back
Data Modernisation

Reliable database management for modern, high-performance systems.

Back
Data Engineering

Reliable database management for modern, high-performance systems.

Back
Analytics & Intelligence

Reliable database management for modern, high-performance systems.

Back
Data Strategy Consulting

Reliable database management for modern, high-performance systems.

Database Tiering on AWS: Archiving MySQL Data to Amazon S3 as Parquet

Kailashwaran R
Published on
November 24, 2026

Operational databases keep growing. Old rows are rarely queried, but they still take up expensive storage, slow down backups and make maintenance harder. This post walks through a MySQL database tiering pipeline I built on AWS. It moves eligible historical records from Amazon RDS for MySQL into Amazon S3 as Parquet files, checks the archive, and only then deletes the rows from the source database.

The screenshots come from the AWS console while I was building it. The same pattern works for other MySQL estates, with changes to match your tables and retention rules. The services are described on the Amazon Web Services page.

The pipeline at a glance

AWS Step Functions runs the whole archive as one workflow. Each stage has one job, and deletion runs only after validation passes. Our data engineering service covers this kind of pipeline work.

StageMain AWS serviceWhat it does1. Metadata discoveryAWS LambdaIdentifies eligible tables.2. Dependency discoveryAWS LambdaMaps foreign-key relationships between tables.3. Count eligible recordsAWS LambdaCounts the rows to archive. Ends early when the count is zero.4. Glue job executionAWS GlueReads from MySQL over JDBC and writes Parquet to S3, partitioned by year.5. Archive validationAWS Lambda and Amazon AthenaChecks the archived data in S3 before any delete.6. Record deletionAWS LambdaDeletes archived rows from MySQL, children before parents.7. Verification and cleanupAWS Lambda and Amazon SNSConfirms the deletion, removes the validation file and sends the success notification.

Archival workflow from metadata discovery to verification
Figure 1: Archival workflow from metadata discovery to verification.

Why tier old data

  • Storage cost: recent records must stay fast and available in MySQL. Historical records do not need that level of service.
  • Retention: old data is expensive to keep in a transactional database, but it must stay queryable for audits and reporting.
  • Safety: deleting rows is risky when foreign keys exist, and deleting before verifying the archive risks permanent data loss.

The goal was a repeatable, orchestrated process: discover what to archive, copy it to cheaper columnar storage, prove the copy is correct, and only then delete. Our database performance tuning services cover performance work on MySQL and other engines.

AWS services used

  • Amazon RDS for MySQL: the source operational database. Read more about AWS RDS and MySQL.
  • AWS Secrets Manager: stores database credentials, so they are never hard-coded.
  • AWS Lambda: configuration discovery, record counting, validation, deletion and verification logic.
  • AWS Glue: JDBC extraction from MySQL and conversion to Parquet.
  • AWS Step Functions: workflow orchestration, branching and error handling.
  • Amazon S3: a year-partitioned Parquet archive.
  • Amazon Athena and the Glue Data Catalog: query and validate the archived data.
  • Amazon SNS: success and failure notifications.
  • AWS IAM: least-privilege roles for Lambda, Glue and Step Functions.

Keeping credentials out of code

Database credentials are kept in AWS Secrets Manager. The secret stores the standard RDS key set: username, password, engine, host, port and dbInstanceIdentifier. Lambda reads it at runtime, so no credentials appear in code or in environment variables.

Secret structure in AWS Secrets Manager, key names only
Figure 2: Secret structure in AWS Secrets Manager (key names only; secret values are not shown).

The db-tiering-read-config Lambda function receives the secret name through an environment variable (SECRET_NAME). It calls the Secrets Manager API with boto3, parses the returned JSON and uses PyMySQL to connect to the database. The PyMySQL library is packaged with the function code.

Lambda handler retrieving the database secret with boto3
Figure 3: Lambda handler retrieving the database secret with boto3.
Function overview after deployment of db-tiering-read-config
Figure 4: Function overview after a successful deployment of db-tiering-read-config.

The AWS Glue extraction job

The extraction is done by an AWS Glue job named employees-rds-to-s3-parquet. I created it in Glue Studio with a JDBC data source named Relational-DB. It connects through a Glue connection (Mysql-connection) to the employees table. The job runs under a dedicated IAM role created for the RDS MySQL to S3 archival pipeline.

Glue Studio visual editor with the JDBC data source and the employees table
Figure 5: Glue Studio visual editor with the JDBC data source and the employees table.
Data source properties and the IAM role used for the Glue job
Figure 6: Data source properties and the IAM role used for the Glue job.

The Glue script tab shows the standard Glue boilerplate: GlueContext and Spark session setup, argument parsing with getResolvedOptions, and job initialisation and commit. The extraction and Parquet write steps run on top of this skeleton.

Glue job script showing job initialisation and commit
Figure 7: Glue job script showing job initialisation and commit.

Workflow orchestration with AWS Step Functions

Rather than run each step by hand, I modelled the whole archival lifecycle as a Step Functions state machine, db-tiering-state-machine. The final design has these stages:

  1. Metadata discovery identifies eligible tables.
  2. Dependency discovery identifies relationships and foreign-key dependencies.
  3. Count eligible records counts the records for archival and ends with NoRecordsFound when there are none.
  4. Glue job execution starts the job with StartJobRun, then runs a Wait and GetJobRun polling loop until the job completes.
  5. Archive validation checks the data written to S3.
  6. Record deletion removes archived records from MySQL in dependency-safe order.
  7. Verification and cleanup checks the deletion, removes the validation file and publishes the success notification.

Every critical state has a Catch path that routes to SNS notifications and a Fail state. Choice states gate each stage, so deletion can never run unless validation passed.

Complete state machine design with Lambda tasks, Glue polling loop and SNS failure paths
Figure 8: Complete state machine design, with Lambda tasks, the Glue polling loop, validation and deletion gates, and SNS failure paths.

The earlier iteration with a crawler

An earlier version of the workflow also had a Glue crawler step to register the archived data in the Data Catalog. In that run every state completed successfully, including the Glue job and crawler polling loops.

Earlier workflow iteration with a Glue crawler, all states succeeded
Figure 9: Earlier workflow iteration with a Glue crawler. Every state succeeded.

Eligible records and the Glue job start

The CountEligibleRecords task received an empty input and returned statusCode 200 with eligible_records equal to 10000. Because the value is greater than zero, the AnyRecords? Choice state routed execution to StartGlueJob.

State input and output for CountEligibleRecords showing 10000 eligible records
Figure 10: State input and output for CountEligibleRecords in a Step Functions execution.
Execution graph during StartGlueJob with the Glue job run response
Figure 11: Execution graph during StartGlueJob, with the Glue job run response.

Parquet archive on Amazon S3

The Glue job writes the archive to an S3 bucket using a Hive-style layout: archive/testdb/testdb_employees/archive_year=YYYY/. Partitioning by year keeps the data organised and lets Athena skip partitions it does not need. The console shows partitions for 2020 through 2024.

Archived employees data in S3 partitioned by archive_year from 2020 to 2024
Figure 12: Archived employees data in S3, partitioned by archive_year (2020 to 2024).

Validating the archive with Amazon Athena

To prove the archive is correct before any deletion, I queried it with Athena through the db_tiering_archive database in the Glue Data Catalog. The employees table is registered as partitioned. A simple COUNT(*) returned 10000, which matches the eligible_records value from the Step Functions execution.

Athena query SELECT COUNT(*) FROM employees returning 10000
Figure 13: Athena validation query. SELECT COUNT(*) FROM employees returns 10000 records.

Dependency-aware deletion and verification

Only after validation passes does the workflow call the deletion Lambda. Relational tables reference each other, so rows are deleted in dependency-safe order, children before parents, based on the output of the dependency discovery step. A verification Lambda then confirms the deletion before the workflow publishes its success notification. If any step fails, the Catch paths send a failure notification and the workflow ends in a Fail state, so partial deletions are visible rather than silent.

Limits to know

LimitWhat it meansWhat to do insteadSingle-connection readsBy default, Glue reads a whole MySQL table through one JDBC connection. On large tables this can be slow or fail with lost nodes.Test a parallel read on a copy of the largest table. AWS suggests a hash-based split with hashexpression and hashpartitions.Manual pollingStep Functions also has a built-in .sync integration for Glue job runs.This pipeline polls explicitly, which gives a separate branch for each job state. Both approaches are valid.Secret keysThe keys inside a secret depend on how it was created.Check the live secret in your account before you wire up the Lambda.Job commitGlue job bookmarks record progress only when the script calls job.commit().Keep the commit call at the end of every Glue script.

Lessons from the build

  • Glue job runs must be polled explicitly. A Wait and GetJobRun loop with a Choice state handles succeeded, failed, stopped and timed-out outcomes cleanly.
  • Safe deletion needs the right order. Foreign keys make dependency discovery an essential step, not an optional one.
  • Never delete before validating. Placing archive validation as a gate in front of the deletion step is the most important safety control in the design.
  • Keep secrets out of code. Secrets Manager and least-privilege IAM roles removed credentials from the codebase.
  • Redact before publishing. Account IDs, ARNs and connection details should be masked in any screenshot you share.

Before a migration or archive run, a checklist helps. Our database migration checklist is a useful starting point.

Where this fits in a DBA's day

  • Start with one low-risk table in a test environment, and compare row counts from source and archive before any delete.
  • Map foreign keys first. Dependency discovery is not optional.
  • Keep the validation gate in front of every delete.

If the archive is part of a wider move, read data migration without data loss before you start, and our cloud database migration service page.

Wrapping up

Database tiering on AWS is a practical pattern: discover, extract, validate, delete and verify, all orchestrated by Step Functions and built on managed services. Hot data stays fast in MySQL. Historical data lives cheaply in S3 as partitioned Parquet, and it stays queryable through Athena.

If you are planning a similar archive for your MySQL estate, the Geopits team can review the design with you. Start with a free database audit, or contact us. More practical posts are on the Geopits blog.

FAQ

1. What is database tiering?
Database tiering moves rarely used data from a fast, expensive database to cheaper storage, while keeping it available for queries.

2. Why store the archive as Parquet in Amazon S3?
Parquet is a columnar, compressed format. Athena reads only the columns a query needs, so archived data stays cheap to query.

3. Why does the pipeline validate before deleting?
A delete in the source database cannot be undone from the archive. Validation proves the copy is correct, and it gates the delete step.

4. Why are child tables deleted before parent tables?
Foreign keys block the deletion of a parent row while child rows still reference it. Dependency discovery finds the right order.

5. Can Athena query the archived data?
Yes. The Glue Data Catalog registers the table, and Athena queries the S3 partitions directly.

6. What should I test before running this in production?
Test on a copy of the schema, compare row counts from source and archive, check the foreign-key order, exercise the failure paths, and confirm the secret keys and IAM permissions.

Related reading

Sources

AWS Step Functions, Start an AWS Glue job; AWS Glue, JDBC connections; AWS Knowledge Center, Glue lost nodes in an RDS to S3 migration; Amazon RDS, Password management with Secrets Manager.

Kailashwaran R

Kailashwaran R

Kailashwaran R specializes in database administration, with a focus on database management, monitoring, and performance optimization. His technical interests include maintaining database reliability, supporting database operations, and ensuring efficient and secure database environments.

Our Latest Blogs

From monitoring to modernization, GeoPITS provides expert database management services that enhance performance, strengthen security, and reduce operational costs.

Ready to Transform Your Data?

Geopits works alongside your team as a strategic partner, starting with stabilizing your current databases, then modernizing your data infrastructure, and ultimately helping you unlock the full potential of AI.

170

Happy Clients so far

2100+

Databases Managed

142+

Successful Migrations

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.