Can I delete data rows in tables from Athena?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Amazon Athena is a powerful interactive query service that enables you to analyze data in Amazon S3 using standard SQL. One question that often arises for users is: "Can I delete data (rows in tables) from Athena?" Here, we will explore how Athena works regarding data deletion and offer insights into its operational environment.
Understanding Athena's Architecture
Before diving into data deletion, it's crucial to understand how Amazon Athena operates:
- Query Execution: Athena is based on Presto, allowing users to execute queries using standard SQL.
- Data Storage: Unlike traditional databases, Athena lacks its own persistent storage. It operates on data stored in Amazon S3.
- Read-Only Nature: Athena is designed primarily for reading and querying data, not for modifying or deleting it directly within its interface.
Why Can't You Delete Directly from Athena?
Athena as a Query Engine: Since Athena is a query engine that leverages S3 for data storage, it does not possess the inherent ability to modify or delete data directly. Athena is utilized for analysis, and any data manipulation must be conducted through S3 or another data management service.
Alternatives for Deleting Data
- Amazon S3: Direct interaction with S3 buckets is the primary method for data deletion.
- You can manage the data lifecycle by utilizing bucket policies, object expiration, or versioning to remove unnecessary data.
- Manual deletions via the AWS Management Console, CLI, or SDK can also be executed.
- ETL Processes: Use AWS Glue or an external Extract, Transform, Load (ETL) tool.
- Data Transformation: Extract data from S3, remove or transform it as needed, and store the modified dataset back in S3.
- Batch Deletion: Perform data filtering and reinsertion, thus overwriting the old dataset without the unwanted rows.
- Lake Formation: AWS Lake Formation can help with governed tables.
- Use `DELETE` for Apache Iceberg tables managed by Lake Formation (Experimental support as of 2022).
Example of Deleting Data Using S3 Operations
Assume your dataset is stored in the `my-s3-bucket` in a partitioned manner under paths like:
- Backup Data: Before deleting, ensure data is backed and recoverable.
- Automate Processes: Use AWS Lambda to automate deletion procedures based on certain triggers.
- Retention Policy: Implement stringent policies for data expiration and retention.
- Test First: Always perform changes in a development or testing environment to avoid accidental loss.
Related reading
- Can I force CloudFormation to delete non-empty S3 Bucket?
- Can I limit concurrent invocations of an AWS Lambda?
- Can I pause an ECS service instead of deleting it?
- Can I remove the public IP on my instance without terminating it?
- Can I force cleanup of old tombstones?
- Can I generate script of a migration with EF code first and .net core
- Can I specify an AWS DynamoDB policy based on Cognito ID?
- Can I store a temp file on AWS Lambda Function?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.